I\'m trying to use the shapely.geometry.Polygon
module to find the area of polygons but it performs all calculations on the xy
plane. This is fine
Fyi, here is the same algorithm in Mathematica, with a baby unit test
ClearAll[vertexPairs, testPoly, area3D, planeUnitNormal, pairwise];
pairwise[list_, fn_] := MapThread[fn, {Drop[list, -1], Drop[list, 1]}];
vertexPairs[Polygon[{points___}]] := Append[{points}, First[{points}]];
testPoly = Polygon[{{20, -30, 0}, {40, -30, 0}, {40, -30, 20}, {20, -30, 20}}];
planeUnitNormal[Polygon[{points___}]] :=
With[{ps = Take[{points}, 3]},
With[{p0 = First[ps]},
With[{qs = (# - p0) & /@ Rest[ps]},
Normalize[Cross @@ qs]]]];
area3D[p : Polygon[{polys___}]] :=
With[{n = planeUnitNormal[p], vs = vertexPairs[p]},
With[{areas = (Dot[n, #]) & /@ pairwise[vs, Cross]},
Plus @@ areas/2]];
area3D[testPoly]