-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polygon.centroid() #777
Comments
nice investigation :) |
maybe briefly, just FYI, the recommended way to import compas objects is to always to this from "the second level", which is where the public API is defined. these imports should never change. below that level we sometimes reshuffle things if that is necessary. so in this case the recommended option is from compas.geometry import Polygon, Point |
Thanks for the heads-up. I used to do it "correctly", but the problem for me was that I could never get VSCode to properly auto-complete... I remember discussing this extensively with @yck011522 and @gonzalocasas a while back. |
yes, i know, especially with PyLance this is indeed a problem. we are working on that... |
about the centroid... from compas.geometry import Polygon, Point
from compas.geometry import centroid_points, centroid_polygon
polygon1 = Polygon([Point(0.000, -5.536, 1977.967), Point(0.000, 144.352, -0.000), Point(0.000, -148.968, -0.000), Point(0.000, 264.624, 1977.967)])
polygon2 = Polygon([Point(0.000, 144.352, -0.000), Point(0.000, 264.624, 1977.967), Point(0.000, -5.536, 1977.967), Point(0.000, -148.968, -0.000)])
print(polygon1.centroid)
print(polygon2.centroid)
print(centroid_points(polygon1))
print(centroid_points(polygon2))
print(centroid_polygon(polygon1))
print(centroid_polygon(polygon2)) the output of 1 and 3 is the same, but i guess you were expecting the outcome of 2 :) |
the polygon object uses unfortunately (apparently), we have not yet established full equivalence between the older functional approach and the newer oo system. this is something that should be resolved in one of the upcoming releases... |
will leave it open as a reminder that the current implementation can lead to unexpected results :) |
@gonzalocasas needs to be discussed in the next dev meeting... |
Describe the bug
Polygon.centroid
returns a strange value for a polygon with 4 points that is self interesecting (see image),Using the same points (of the polygon), but cycled differently we get a polygon that is more conventional...
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I would expect them to have the same centroid.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: