Click here to Skip to main content
15,885,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I identify and remove those four red points drawn in image at below link.
http://pritesharyan.weebly.com/question.html[^]

Those four points make that polygon a concave polygon that’s why I want to remove it.

My goal is to convert concave polygon to convex by removing this kind of point by identifying and removing those points.

IS THERE ANY MATHEMATICAL WAY TO IDENTIFY AND REMOVE THIS KIND OF POINTS?

Thanks.
Posted
Updated 1-Dec-10 0:45am
v9

1 solution

To identify such points is quite simple:


  1. consider the point Pn and the two segments adiacent to the point; they are S1 = Pn - Pn-1 and S2 = Pn+1 - Pn
  2. now consider the scalar and vectorial product of the two segments:

    • S1 * S2 = |S1| * |S2| * cos(alpha)
    • S1 ^ S2 = |S1| * |S2| * sin(alpha)

    where alpha is the angle that S1 must be rotated by to get aligned to S2
  3. to compute the scalar and vectorial products, we will use the formula below:

    • S1 * S2 = (X1 - Xn-1) * (Xn+1 - Xn) + (Yn - Yn-1) * (Yn+1 - Yn)
    • S1 ^ S2 = (Xn - Xn-1) * (Yn+1 - Yn) - (Yn - Yn-1) * (Xn+1 - Xn)
  4. now, to get alpha you can use the following formula:

      alpha = atan2(S1 ^ S2, S1 * S2) = atan2(sin(alpha), cos(alpha))
  5. finally, the point Pn should be removed if the value obtained for alpha is greater than zero and your sequence of points describe a clock-wise polygon or, if the value of alpha is less than zero and your sequence of points give a counterclock-wise polygon
 
Share this answer
 
v3
Comments
Pritesh Aryan 1-Dec-10 7:00am    
First of all thank you so much and you had helped me second times so thanks again Sauro,

My question is,
what is atan2 here?
is it [invers tan(theta)]?
i can't understand the presents of 2 here??
Sauro Viti 1-Dec-10 7:35am    
atan2 is not the inverse tan(theta); its signature is atan2(y, x) and it gives the angle (in radians) whose sin is y and whose cosine is x (it works properly also if both x and y are scaled by the same constant).
For more details see http://msdn.microsoft.com/en-us/library/88c36t42(VS.71).aspx
Pritesh Aryan 1-Dec-10 8:13am    
hi Sauro Thanks for Replying But Some Queries,
1. Here what is the use of 2nd step? whereas 3rd step gives us Value of alpha? 2. And in 2nd Step what should i have to use? scalar product or vectorial product or both? Thanks.....
Sauro Viti 1-Dec-10 15:41pm    
I updated my answer to make clear how the scalar and vectorial products are used in the angle evaluation. I hope it's understandable now :-)
Pritesh Aryan 2-Dec-10 0:58am    
Than you so much saurro.........

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