Re: polygonCentroid issues

Nicholas Jankowski <[email protected]>
Newsgroups gmane.comp.gnu.octave.maintainers
Message-ID <CABNpfR-5nB5eUro2iS73SS_zKa_hu7SZkytWwsgeweT3k14DUQ@mail.gmail.com>
>
>
> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.