I have switched over from Python's Shapely to JavaScript's PaperJS. I would like to find the centroid of polygon or closed Path as it is called PaperJS. Is there a quick way to do it or will I have to write my own algorithm?
Asked
Active
Viewed 538 times
0
-
Did you read the paper.js documentation? What did that say about the API for paths/polygons? – Mike 'Pomax' Kamermans Oct 18 '19 at 17:59
-
1A quick google brings up the algorithm https://jsfiddle.net/Xotic750/KtzLq/, but proceed with caution, as it's not clear (at least to me) that it actually produces the centroid. Also, if you are shifting to a new library, you might want to consider the jump to threejs, which appears to have a built-in centroid function. See https://stackoverflow.com/questions/25267003 . – Trentium Oct 19 '19 at 21:22
1 Answers
0
Have you looked on the bounding box created by the poligon path?
Each item created in Paperjs has a bounds property that returns a Rectangle object, this Rectangle object will have a center property that returns the center of the object
Hope that helps

Ricardo Sanchez
- 4,935
- 11
- 56
- 86
-
The centroid is the geometric center of a shape. Paper.js returns the center of the bounds when called path.bounds.center. – northamerican Dec 07 '19 at 01:51