golang / geo

S2 geometry library in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

polylines match

nakulmandal opened this issue · comments

Hi,
what is the recommended way to find two polylines (intersecting each other) are in same direction.
Is there any function written for it?

Can you be more specific?

Hi David,

I got two routes as polylines as lists of coordinates such as: [13.072624,52.333508,13.763972,52.679616] [52.679616,13.763972,52.333508,13.072624]

I need to compare the direction of two polylines. To do so I thought to get the angle between them and return true (going in the same direction) if it is smaller 45°.

example of route comparison==> https://i.stack.imgur.com/LDczR.png

How can I match two routes (means their direction are same or not)

Note that a polyline is a sequence of edges, but your example is only a pair of vectors.

You can take the dot product of two vectors to get the angle between them. The r3.Vector type has a Dot method for that. See https://en.wikipedia.org/wiki/Dot_product for more detail.