How do I choose a normal vector (2d) that points inside any convex polygon?

Ok I have some programming, cyrus-beck algorithm. This algorithm needs normal vector

one that points inside any convex polygon.

Now I just check the function, checks if the point is inside or outside the edge.

This question tell me how to compute a normal vector, but it gives me two results. and I am still trying to choose which vector I should use.

what are the criteria for a normal vector pointing inside a polygon?

Is there any formula / way to calculate the normal (point inside) for any edge in a polygon?

Please clarify the explanation, because I am not very good at vector and mathematical materials.

+3


source to share


1 answer


If you have n points p [] clockwise, then in order to point the cursor inward towards the edge between points p [i] and p [i + 1], you rotate the vector p [i] → p [i + 1 ] clockwise to 90 degrees. I.e:

double dx = p[i+1].x - p[i].x; // x component of edge
double dy = p[i+1].y - p[i].y; // y component of edge
double ndx = dy; // x component of normal
double ndy = -dx; // y component of normal

      



(note that the last edge uses p [n-1] and p [0] (in that order)).

If instead you have points in counterclockwise order, negate both components of n.

+3


source







All Articles