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

Point2 in Polygon gives bad result. #220

Open
valegnr opened this issue Sep 3, 2024 · 1 comment
Open

Point2 in Polygon gives bad result. #220

valegnr opened this issue Sep 3, 2024 · 1 comment

Comments

@valegnr
Copy link

valegnr commented Sep 3, 2024

I am unsure if i am using your code correctly, but i assume that the following code behaves different to what i would expect:

using GeometryBasics,StableRNGs

rng = StableRNG(123) 

results_tri = Vector{Bool}(undef,100)
results_poly = Vector{Bool}(undef,100)
for i in eachindex(results_tri)
    xs = sort(rand(rng,Float32,3))[[1,3,2]] #sorting for orientation of area
    ys = sort(rand(rng,Float32,3))
    points = Point2.(xs,ys)
    tri = Triangle(points...)
    pol = Polygon(points)
    point = 1/3 * sum(points)
    
    results_tri[i] = point in tri 
    results_poly[i] = point in pol 
end

sum(results_tri) == length(results_tri) # returns true
sum(results_poly) == length(results_poly) #returns false

This means to me that in(p::Point2,pol::Polygon) gives a wrong result.
Thank you for your time and effort!

@asinghvi17
Copy link
Contributor

GeometryBasics is meant to be a library that just defines types - try https://github.com/JuliaGeo/GeometryOps.jl or its predecessor https://github.com/JuliaGeometry/PolygonOps.jl for geometry algorithms that work with GeometryBasics!

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

2 participants