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

parry2d::utils::point_in_poly2d gives false negatives #89

Open
kbjakex opened this issue Aug 25, 2022 · 2 comments
Open

parry2d::utils::point_in_poly2d gives false negatives #89

kbjakex opened this issue Aug 25, 2022 · 2 comments

Comments

@kbjakex
Copy link

kbjakex commented Aug 25, 2022

The documentation says:

Tests if the given point is inside of a polygon with arbitrary orientation.

which sounds like it should work with any arbitrary polygon. However, in my application, I have non-convex polygons I tested against, and while there are no false positives, it leaves parts of the polygon out:
Screenshot from 2022-08-25 14-37-10
(the tracing is inexact, I'm just spawning a dot whenever the mouse is detected to be inside the polygon)

Based on the output I'd guess it only works for convex polygons (although I don't understand the algorithm), in which case it would be nice to have a mention of this in the docs.

@ZebTheWizard
Copy link

ZebTheWizard commented Sep 1, 2022

I was having a similar problem where I was defining a list of points. Sometimes the method would return true but it mostly return false. Turns out my points were getting jumbled up. I think this only works if the points are defined in sequence clockwise or counter clockwise. If your points are "zig zagged" then it won't work.

If the method should handle concave and convex shapes, this makes sense because changing the sequence of points creates a different shape.

image

By arbitrary, I think they meant the ordering doesn't matter. For example, the following sequences all form the same polygon:

[[ 1, 1], [-1, 1], [-1,-1], [ 1,-1]]
[[-1, 1], [-1,-1], [ 1,-1], [ 1, 1]]
[[-1,-1], [ 1,-1], [ 1, 1], [-1, 1]]
[[ 1,-1], [ 1, 1], [-1, 1], [-1,-1]]

@sebcrozet
Copy link
Member

This function only supports convex polylines, yeah. We should specify that in the docs. For non-convex (non-self-intersecting) polylines, you can use Polyline::project_local_point_assuming_solid_interior_ccw](https://docs.rs/parry2d/0.9.0/parry2d/shape/struct.Polyline.html#method.project_local_point_assuming_solid_interior_ccw). This method requires the polyline’s orientation to be counterclockwise.

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

No branches or pull requests

3 participants