In 2D, each vector (x, y) has two normals: (-y, x) and (y, -x), pointing in opposite directions.

Say I have a polygon and for each of it's edges I need to get the normal pointing outwards. In the picture below, the red normals:

enter image description here

For each edge of the shape, how can I decide if I need (-y, x) or (y, -x)?


If you have your edges so that they run in a certain direction, either clockwise or anticlockwise, then your normal-generating routine should always be able to work out which points in and which points out. In the about picture, going clockwise from the top point, then the normal pointing outwards will always be 90degrees anticlockwise.

Hope that helps.

Edit: By running in a direction I mean something like a->b->c->d->a.

  • \$\begingroup\$ Not sure I understand. What would the normal generation method look like? \$\endgroup\$ – Aviv Cohn Jun 23 '14 at 16:01
  • \$\begingroup\$ So, you have your points, and because of how you have made your polygon you can cycle around them. Your midpoint is just (a.x+b.x)/2,(a.y+b.y)/2. You get the direction of the normal by -(b.y-a.y),(b.x-a.x) then normalise it as needed. \$\endgroup\$ – Dave Jun 23 '14 at 16:04
  • \$\begingroup\$ In my previous comment I assumed you'd make the polygon going clockwise, btw. \$\endgroup\$ – Dave Jun 23 '14 at 16:20
  • \$\begingroup\$ The missing info is that the vertex winding order defines which face of the polygon is front and which face is back, so (assuming that the polygon is planar) you can use the first 3 vertices (which will be different for CW winding to what they are for CCW winding) to calculate the normal. \$\endgroup\$ – Maximus Minimus Jun 23 '14 at 18:44
  • \$\begingroup\$ I think he's talking about a 2D space, and normals from each edge. Could be wrong, though. \$\endgroup\$ – Dave Jun 23 '14 at 23:07

1st find the center of the polygon. Then find both normals of all the sides. Now consider a side and transform both of its normals to the center of the considered side. Now the normal which is nearer to the center will be directing inside and which is not near will be directing outwards. I hope it helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.