4

Okay, I have a programming assignment, cyrus-beck algorithm. This algorithm needs normal vector that point to inside any convex polygon.

Now i just in checking function, checks whether the point is inside or outside the edge.

This question tell me how to calculate the normal vector, but it gives me two results. and I still struggling to choose which vector should I use.

what is criteria of normal vector that point to inside the polygon?

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

Please go easy with the explanation, because I don't really understand about vector and math stuff.

Community
  • 1
  • 1

1 Answers1

2

If you have the n points p[] in clockwise order, then to get the inward pointing normal to an edge between points p[i] and p[i+1] you rotate the vector p[i]->p[i+1] clockwise through 90 degrees. That is:

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 the points in anticlockwise order, negate both components of n.

dmuir
  • 4,211
  • 2
  • 14
  • 12