# Unexpected behavior of the procedure Area on the object 'Polygon'

Bug introduced in 11.3 or earlier and fixed on 12.0.

Sometimes get a results, sometimes left unevaluated.

For instance

 Area@Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]


12

Transpose@(a.b.Transpose[#]) & /@ Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]


(a,b - some 2x2 matrices)

Polygon[{{0, 0}, {8, -64}, {18, -24}, {36, -48}, {28, 16}}]

Area@(Transpose@(a.b.Transpose[#]) & /@ Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}] )


Area[Polygon[{{0, 0}, {8, -64}, {18, -24}, {36, -48}, {28, 16}}]]

Area@Polygon[{{0, 0}, {8, -64}, {18, -24}, {36, -48}, {28, 16}}]


(copy and paste)

1440

How to guess when a calculation will give a result and when it will not be evaluated? And why does it not evaluate?

• What are the definitions of a and b? – MarcoB Mar 22 '19 at 14:36
• If you want to experiment with this and I haven't made a mistake then it looks like his a.b == {{2,7},{-16,4}} This seems to reproduce his results. – Bill Mar 22 '19 at 16:15

This is a packed array issue:

Area @ Polygon[DeveloperToPackedArray @ {{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]


Area[Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]]

This will be fixed in M12.

• It was a bug and it was fixed! It works expectionally at 12.0 Thank you, thank Mathematica, thank Wolfram! – Slepecky Mamut Apr 26 '19 at 5:24

EDIT: Reported to WRI as CASE:4237867 - fixed on V12. :)

Seems like a bug in my opinion. Consider the following:

With[{poly0 = Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]},
With[{poly = Transpose[IdentityMatrix.Transpose@#] & /@ poly0},
{poly0 === poly, Area /@ {poly0, poly}}]]


{True, {12, Area[Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]]}}

Although the Mma considers poly0 and its transformed but identical copy (coordinates transformed using IdentityMatrix) identical, they produce different results.

Probably the internal representation of poly is not the same as poly0. At the same time its output form is identical, which actually transforms it to other form if you copy and paste it.

This can be further simplified to show that from the perspective of Polygon two semantically identical coordinate lists can differ:

With[{coord0 = {{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}},
With[{coord = Transpose[IdentityMatrix.Transpose@coord0]},
{coord0 === coord, Area@*Polygon /@ {coord0, coord}}]]


{True, {12, Area[Polygon[{{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}]]}}

I suspect there's something wrong with the way Polygon reads the internal representation of a list!

EDIT: I think there's a good chance this problem is caused by the fact coord is a packed array, while coord0 is not:

With[{coord0 = {{0, 0}, {4, 0}, {2, 2}, {4, 4}, {0, 4}}},
With[{coord = Transpose[IdentityMatrix.Transpose@coord0]},
{coord0 === coord, DeveloperPackedArrayQ /@ {coord0, coord},
Area@*Polygon /@ {coord0, DeveloperFromPackedArray@coord}}]]


{True, {False, True}, {12, 12}}

So, you can use FromPackedArray` on the transformed coordinate list as a workaround.