Function Repository Resource:

PolygonNormalVector

Source Notebook

Compute the normal vector to a 3D polygon

Contributed by: Jan Mangaldan

ResourceFunction["PolygonNormalVector"][poly]

gives the normal vector to the 3D polygon poly.

Details and Options

poly can be a Polygon or a Triangle object.
The vector returned by ResourceFunction["PolygonNormalVector"] is always normalized to have unit length.
ResourceFunction["PolygonNormalVector"] accepts a Method option.
Method"Newell" uses Newell's method to compute the normal vector.
Method"SVD" uses singular value decomposition to compute the normal vector.

Examples

Basic Examples (2) 

Compute the normal vector to a triangle:

In[1]:=
poly = Polygon[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}}];
nrm = ResourceFunction["PolygonNormalVector"][poly]
Out[1]=

Visualize the polygon and its normal:

In[2]:=
Graphics3D[{poly, With[{cen = Mean @@ poly}, Arrow[Tube[{cen, cen + nrm}]]]}]
Out[2]=

Scope (2) 

PolygonNormalVector works on Triangle objects:

In[3]:=
ResourceFunction["PolygonNormalVector"][
 Triangle[{{0., 0., 0.}, {1., 0., 0.}, {0., 1., 0.}}]]
Out[3]=

PolygonNormalVector works on any 3D polygon:

In[4]:=
ResourceFunction["PolygonNormalVector"][
 Polygon[{{1., 0., 0.}, {0.3, 0.3, 0.4}, {0., 1., 0.}, {0., 0., 1.}}]]
Out[4]=

Options (1) 

Method (1) 

Compare the different methods of computing a normal vector:

In[5]:=
poly = Polygon[
   N[PadRight[CirclePoints[5], {Automatic, 3}] . RollPitchYawMatrix[{-\[Pi]/6, -\[Pi]/4, -\[Pi]/3}]]];
In[6]:=
Table[Graphics3D[{poly, With[{cen = Mean @@ poly}, Arrow[Tube[{cen, cen + ResourceFunction["PolygonNormalVector"][poly, Method -> met]}]]]}, PlotLabel -> met], {met, {"Newell", "SVD"}}]
Out[6]=

Applications (1) 

Visualize the normal vectors for a model of Beethoven:

In[7]:=
bust = ExampleData[{"Geometry3D", "Beethoven"}, "GraphicsComplex"];
In[8]:=
Graphics3D[{bust, {Directive[Arrowheads[Tiny], GrayLevel[0.2]], With[{c = Mean[First[#]]}, Arrow[Tube[{c, c + 0.4 ResourceFunction["PolygonNormalVector"][#]}]]] & /@ First[Normal[bust]]}}, Boxed -> False]
Out[8]=

Version History

  • 1.0.0 – 04 March 2021

Source Metadata

Related Resources

License Information