Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to check if the polygon is not intersected itself, how to do this with C++ or C#? Thanks.
Posted
Comments
agent_kruger 22-Feb-14 10:44am    
what have you tried so far? and the code to create the polygon?
Andrewpeter 22-Feb-14 10:53am    
I created the polygon with n points given (x1, y1),...,(xn, yn). I dont know any algorithm to check if the polygon is intersected or not intersected itself.
agent_kruger 22-Feb-14 13:24pm    
is the polygon side specific in number?

1 solution

If you mean "how do I detect a self-intersecting polygon?" such as an hourglass:

X------>X
 ^     /
  \   /
   \ /  
    \
   / \
  /   \
 v     \
X------>X
Then it's non-trivial. But...several algorithms exist, including Bentley-Ottmann which is described here: http://geomalgorithms.com/a09-_intersect-3.html[^]

You may be able to find a suitable C++ or C# implementation via Google - I haven't looked - but it might be easier to write your own, the pseudocode examples look reasonably simple to follow.

[edit]Drew arrow head on wrong end... :doh: [/edit]
 
Share this answer
 
v2
Comments
Andrewpeter 27-Feb-14 21:03pm    
It's great. Thanks. My vote is 5.
OriginalGriff 28-Feb-14 3:20am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900