# How to get the normal that points *out* of a polygon

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:

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.

• Not sure I understand. What would the normal generation method look like? Commented Jun 23, 2014 at 16:01
• 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.
– Dave
Commented Jun 23, 2014 at 16:04
• In my previous comment I assumed you'd make the polygon going clockwise, btw.
– Dave
Commented Jun 23, 2014 at 16:20
• 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. Commented Jun 23, 2014 at 18:44
• I think he's talking about a 2D space, and normals from each edge. Could be wrong, though.
– Dave
Commented Jun 23, 2014 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.