geometrymapsjts

How to check if two wkb geometries form an arc of a circle instead of an S shape?


I have two wkb geometries.

geometry1:

010200000044000000B4493437958B0E4019D69EA39F59494023B1EE69988B0E4031467FC39F5949407307FBC09F8B0E402B9DB415A05949400A9A3B9FA68B0E400DB21B6CA05949404E76D8E9AC8B0E40D784B4C6A05949408D953DAEB28B0E408A157F25A159494078FEFEDEB78B0E40FBE4CD86A1594940C3B7B06EBC8B0E4054724EECA1594940BBBABE6AC08B0E40D77E7C53A2594940C61451B8C38B0E4018CA2EBDA25949402FBFD364C68B0E4018546529A3594940ABC0DA62C88B0E40AC9D7296A35949408712D2BFC98B0E406B662D05A459494075BB4D6ECA8B0E40292FE873A459494075BB4D6ECA8B0E40E7F7A2E2A45949408712D2BFC98B0E403A803452A5594940ABC0DA62C88B0E40648918C0A55949402FBFD364C68B0E40F8D2252DA6594940C61451B8C38B0E40F85C5C99A6594940BBBABE6AC08B0E4039A80E03A7594940C3B7B06EBC8B0E405174136BA759494078FEFEDEB78B0E401542BDCFA75949408D953DAEB28B0E401BD1E231A85949404E76D8E9AC8B0E40CD61AD90A85949400A9A3B9FA68B0E40983446EBA85949407307FBC09F8B0E407A49AD41A959494023B1EE69988B0E4074A0E293A9594940CE9DAA8C908B0E40F1790FE1A9594940C0C69A36888B0E40F0D53329AA594940951E97827F8B0E4073B44F6CAA594940FFAB3363768B0E40E4558CA9AA5949404B68DCE56C8B0E40D879C0E1AA594940C74CFD17638B0E4025A13E13AB594940C1520207598B0E40CCCB063EAB594940847357C04E8B0E4061B9EF62AB594940C5B59036448B0E40E469F981AB5949401E0C8684398B0E402B5E7699AB594940DC6FA3B72E8B0E40CC553DAAAB59494000E1E8CF238B0E40C6504EB4AB59494023522EE8188B0E40AE0E80B8AB594940F9C907F30D8B0E40C6504EB4AB5949401C3B4D0B038B0E40CC553DAAAB594940DA9E6A3EF88A0E402B5E7699AB59494033F55F8CED8A0E40E469F981AB594940C1300510E38A0E4061B9EF62AB5949403858EEBBD88A0E40CCCB063EAB594940315EF3AACE8A0E4025A13E13AB594940AD4214DDC48A0E40D879C0E1AA594940F9FEBC5FBB8A0E40E4558CA9AA594940638C5940B28A0E4073B44F6CAA59494038E4558CA98A0E40F0D53329AA5949407806B243A18A0E40F1790FE1A959494023F36D66998A0E4074A0E293A959494086A3F501928A0E407A49AD41A9594940EE10B5238B8A0E40983446EBA8594940AA3418D9848A0E40CD61AD90A85949406C15B3147F8A0E401BD1E231A859494080ACF1E3798A0E401542BDCFA759494035F33F54758A0E405174136BA75949408AE99D65718A0E4039A80E03A7594940808F0B186E8A0E40F85C5C99A659494016E5886B6B8A0E40F8D2252DA65949404DEA1560698A0E40648918C0A5594940BF918A10688A0E403A803452A5594940D1E80E62678A0E40E7F7A2E2A4594940D1E80E62678A0E40292FE873A4594940BF918A10688A0E406B662D05A45949404DEA1560698A0E40AC9D7296A3594940

geometry2:

0102000000070000004DEA1560698A0E40AC9D7296A359494016E5886B6B8A0E4018546529A3594940808F0B186E8A0E4018CA2EBDA25949408AE99D65718A0E40D77E7C53A259494035F33F54758A0E4054724EECA159494080ACF1E3798A0E40FBE4CD86A15949406C15B3147F8A0E408A157F25A1594940

I need to check whether they form an arc(C shape) instead of an S shape. How can I achieve this with only the wkb information.


Solution

  • Check that for all triplets of subsequent points P[i], P[i+1], P[i+2] polyline makes turn of the same direction (either all left, or all right turns).

    For example, you can check sign of cross product of vectors P[i+1]- P[i] and P[i+2]- P[i+1].
    In coordinates:

    cp = (P[i+1].X-P[i].X)*(P[i+2].Y-P[i+1].Y)-(P[i+1].Y-P[i].Y)*(P[i+2].X-P[i+1].X)