user2189186
user2189186

Reputation:

Detect Intersection points when drawing a polygon by mouse inside rectangular area

I am drawing a polygon where each vertex is given my mouse click inside a rectangular area. I need to track that non adjacent nodes of polygon should not intersect and polygon should remain inside rectangular area i.e in either case the point/vertex if selected will be removed.I am trying hard but not able to find any algorithm/code for the problem.If anyone have the solution please let me know. Thanks

Upvotes: 0

Views: 254

Answers (1)

StanislavL
StanislavL

Reputation: 57381

You should check whether any of the polygin's line intersects another. Create a list of lines for each pair of vertexes. Go through the list and check whether curent line intersects any following line.

To check whether it's intersects the rectangular area do the same. Check whether any of the polygon lines intersects the 4 of rectangle's lines.

Upvotes: 1

Related Questions