octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: polygonCentroid issues


From: Nicholas Jankowski
Subject: Re: polygonCentroid issues
Date: Sat, 2 May 2020 15:13:22 -0400


Can anyone explain to me why the solution for the "polygonCentoid" function
attains a results which is incorrect?
<https://octave.1599824.n4.nabble.com/file/t373111/polygon.jpg
 
Better to copy/paste the text than an image of text.  But, it looks like polygonCentroid doesn't like the crossover topology of your bowtie.  If you reorder your points so that it traces a perimeter without crossing over the center (even with the center points on top of each other) it seems to give a more reasonable answer.  I don't know if that is the function's expected behavior.  It seems to use enclosed area to determine centroid, and without diving into the code I don't know how the crossover messes up it's area calculation.

For everyone else, here was your code (to the numerical precision I could copy):
>> pkg load matgeom
>> poly = [4 0; 4 -.12466; 4.49821 0; 5 .12556; 5 0; 4.49821 0; 4 0]
poly =

   4.00000   0.00000
   4.00000  -0.12466
   4.49821   0.00000
   5.00000   0.12556
   5.00000   0.00000
   4.49821   0.00000
   4.00000   0.00000

>> drawPolygon(poly)
>> polygonCentroid(poly)
ans =

   50.9457    5.8111

switching the order of points 4 and 5:

>> poly = [4 0; 4 -.12466; 4.49821 0; 5 0; 5 .12556; 4.49821 0; 4 0]
poly =

   4.00000   0.00000
   4.00000  -0.12466
   4.49821   0.00000
   5.00000   0.00000
   5.00000   0.12556
   4.49821   0.00000
   4.00000   0.00000

>> drawPolygon(poly)
>> polygonCentroid(poly)
ans =

   4.50179558   0.00044929


reply via email to

[Prev in Thread] Current Thread [Next in Thread]