dgamma3
dgamma3

Reputation: 2371

intersecting polygons and polylines, using google maps API v3

I have a polygon and polyline created dynamically. Now I need to check whether they both intersect each other or not.

How do I achieve this? Googling hasn't provided any satisfactory results.

Thanks Daniel

Upvotes: 0

Views: 5033

Answers (2)

Shabab Qaisar
Shabab Qaisar

Reputation: 60

Look at Turf.js it provides you very simple lineIntersect method you pass it coordinates1, coordinates2 and it gives you the array of exact intersections. Turf.js lineIntersect documentation

Upvotes: 1

antonio
antonio

Reputation: 18262

You need to iterate over each segment of the first polygon/polyline and check if it intersects each segment of the second polygon/polyline. If one intersects, there the two geometries intersect.

If you don't need to take into account geodesic lines, you can take a look at the suggested implementations here: How do you detect where two line segments intersect? (there is also a Javascript implementation that may suit your needs: https://github.com/pgkelley4/line-segments-intersect/blob/master/js/line-segments-intersect.js)

Upvotes: 1

Related Questions