Planar Polygon
Flat polygons embedded in three-space can be transformed into a congruent planar polygon as follows. First, translate the starting vertex to (0, 0, 0) by subtracting it from each vertex of the polygon. Then find the normal n to the polygon by taking the cross product of the first and last vertices. Now, let A be the rotation matrix for Euler angles psi, theta, and phi, and solve
for cospsi and costheta (after first expressing sines in terms of cosines using cosx=sqrt(1-sin^2x). The result is
The signs are chosen as follows:
Plugging these back in and applying to the original polygon then gives a polygon whose vertices all have one component zero. This component can then be dropped. The only special cases which need to be taken into account are |n_z|=1, in which case the polygon is parallel to the xy-plane and the third components can be immediately dropped. The second occurs when n_x=0, in which case there is no component of the normal vector along the x-axis, so the Euler rotation will not work. However, simply picking a different starting vertex from which to calculate the normal resolves this degenerate case.
See also
PolygonExplore with Wolfram|Alpha
Cite this as:
Weisstein, Eric W. "Planar Polygon." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/PlanarPolygon.html