Skip to content
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

convex_hull gives incorrect polygon near poles, maybe #211

Open
spenczar opened this issue Oct 13, 2021 · 1 comment
Open

convex_hull gives incorrect polygon near poles, maybe #211

spenczar opened this issue Oct 13, 2021 · 1 comment
Labels

Comments

@spenczar
Copy link

I am seeing strange behavior with polygon point containment near the poles.

Here's an example. Build a convex hull from points which swing around the north pole at latitude 80:

positions = [radec_to_vector(x, 80) for x in range(360)]
c_hull = SphericalPolygon.convex_hull(positions)

Does the hull contain the north pole? It should...

>>> c_hull.contains_point((0, 0, 1))
False

This looks incorrect to me. Minor perturbations of the north pole sometimes work, and sometimes don't. It seems very inconsistent.

@pllim pllim added the bug label Oct 12, 2023
@mcara
Copy link
Member

mcara commented Oct 30, 2023

Thank you for reporting this. Indeed, after taking a look at the code, this is a limitation of the algorithm. If you modify positions in this way (as an example):

positions = [radec_to_vector(x, 80 + x / 360) for x in range(360)]

the code will work correctly. With your original example, all points are at the same "distance" (in degrees) from the pole and this is where the algorithm fails. You could try applying a rotation to the x, y, z coordinates of your points so that the North pole ((0, 0, 1)) is not inside the convex hull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants