polygonCentroid issues

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

polygonCentroid issues

Mishal0488
Hi Guys

I have a program that I've made whereby various polygons are attained and
the centroid of these polygons are calculated, which is then used for other
calculations.

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>

Kind regards
Mishal Mohanlal



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html

Reply | Threaded
Open this post in threaded view
|

Re: polygonCentroid issues

nrjank

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 | Threaded
Open this post in threaded view
|

Re: polygonCentroid issues

JuanPi
most of the functions in matgeom and geometry assume the polygon is
simple. It is not explicit in the docs, so there is room for
improvement (if you do not want to wait for me you can report the
documentation issue here https://github.com/mattools/matGeom/issues).
The change proposed by Nicholas indeed breaks the polygon into two
simple polygons.