1
$\begingroup$

I have a polygon generated by some data. Sometimes, I cannot compute the area of some of the generated polygons and I cannot correctly apply function NMaxmize on its region either. (For some polygons these work well but they fail to work for specific ones). I wonder why this happens and how to fix it.

For example, this is a successful one

pol = Polygon[{{1.073332569964023`, -1.8576544111276834`, -3.06965`}, \
{-1.0734323825132777`, -1.8576544111276834`, -3.06965`}, \
{-2.0717542556690365`, -3.587970838511705`, \
-0.00008236145274327066`}, {2.0716585508349357`, \
-3.5879842572471317`, -0.00005855672236896324`}, {1.073332569964023`, \
-1.8576544111276834`, -3.06965`}}]

Area[pol]

NMaximize[xi, {xi, yi, zi} \[Element] pol]

whose result is enter image description here

and this is a failed one

pol = Polygon[{{1.073345506818552`, 1.857637206027929`, 
    3.0696499694419788`}, {2.0716892525829143`, 
    3.587975340418905`, -0.00006534259886672701`}, \
{4.1439268249396655`, -0.000023855261707517`, \
-0.00008236145274327066`}, {2.146229106755889`, \
-0.000009315675120787797`, 3.0696499694419788`}, {1.073345506818552`, 
    1.857637206027929`, 3.0696499694419788`}}]

Area[pol]

NMaximize[xi, {xi, yi, zi} \[Element] pol]

whose result is enter image description here

Concerning if all points are in the same plane, I did some tests. Based on my tests(only based on upon several data sets), I found that if all points are exactly in a single plane the issues don't exist, but for points that are not exactly in one plane the issues sometimes appear and sometimes don't. Here are two examples: This is an example where all points are NOT judged to be in one plane and we can compute its area and use NMaximize:

points = {{2.146229106755889`, -9.315675120787797`*^-6, 
    3.0696499694419788`}, {4.1439268249396655`, \
-0.000023855261707517`, -0.00008236145274327066`}, \
{2.0716585508349357`, -3.5879842572471317`, \
-0.00005855672236896324`}, {1.0733325799020568`, -1.857654428352594`, 
    3.0696499694419788`}, {2.146229106755889`, \
-9.315675120787797`*^-6, 3.0696499694419788`}};
pol = Polygon[points]
Area[pol]
NMaximize[xi, {xi, yi, zi} \[Element] pol]
pp = InfinitePlane[Take[points, 3]];
RegionMember[pp, points]

enter image description here

and this is where they are NOT judged to be in one plane either and issues appear:

points = {{2.0716585508349357`, -3.5879842572471317`, \
-0.00005855672236896324`}, {4.1439268249396655`, \
-0.000023855261707517`, -0.00008236145274327066`}, \
{2.1462290868694445`, -9.315675187064002`*^-6, -3.06965`}, \
{1.073332569964023`, -1.8576544111276834`, -3.06965`}, \
{2.0716585508349357`, -3.5879842572471317`, -0.00005855672236896324`}};
pol = Polygon[points]
Area[pol]
NMaximize[xi, {xi, yi, zi} \[Element] pol]
pp = InfinitePlane[Take[points, 3]];
RegionMember[pp, points]

enter image description here

$\endgroup$
1
  • $\begingroup$ I did some tests and added the results in the original questions, please see there. The way I judge if they are in the same plane is that I choose 3 points to construct an infinite plane and judge if all points are in the plane $\endgroup$
    – Dennis
    Commented Dec 19, 2020 at 4:43

1 Answer 1

2
$\begingroup$

DiscretizeGraphics seems work.

pol = Polygon[{{1.073345506818552`, 1.857637206027929`, 
     3.0696499694419788`}, {2.0716892525829143`, 
     3.587975340418905`, -0.00006534259886672701`}, \
{4.1439268249396655`, -0.000023855261707517`, \
-0.00008236145274327066`}, {2.146229106755889`, \
-0.000009315675120787797`, 3.0696499694419788`}, {1.073345506818552`, 
     1.857637206027929`, 3.0696499694419788`}}] // DiscretizeGraphics
Area[pol]

NMaximize[xi, {xi, yi, zi} ∈ pol, Method -> Automatic]

11.0793

{4.14393, {xi -> 4.14393, yi -> -0.0000240063, zi -> -0.0000825525}}

points = {{2.0716585508349357`, -3.5879842572471317`, \
-0.00005855672236896324`}, {4.1439268249396655`, \
-0.000023855261707517`, -0.00008236145274327066`}, \
{2.1462290868694445`, -9.315675187064002`*^-6, -3.06965`}, \
{1.073332569964023`, -1.8576544111276834`, -3.06965`}, \
{2.0716585508349357`, -3.5879842572471317`, -0.00005855672236896324`}};
pol = Polygon[points] // DiscretizeGraphics
Area[pol]
NMaximize[xi, {xi, yi, zi} \[Element] pol]
pp = InfinitePlane[Take[points, 3]];
RegionMember[pp, points]

11.0789

{4.14393, {xi -> 4.14393, yi -> -0.0000238763, zi -> -0.0000827308}}

{True, False, True, False, True}

$\endgroup$
1
  • $\begingroup$ Thanks for the solution. I tested it with my data sets and it indeed works well so far. But it's still unclear to me why it doesn't work out without taking "DiscretizeGraphics" and then works with it. And does "DiscretizeGraphics" possibly cause extra numerical errors? $\endgroup$
    – Dennis
    Commented Dec 19, 2020 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.