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

Line3.intersects(AABB3) #131

Open
eadf opened this issue Sep 17, 2021 · 0 comments
Open

Line3.intersects(AABB3) #131

eadf opened this issue Sep 17, 2021 · 0 comments
Labels

Comments

@eadf
Copy link
Contributor

eadf commented Sep 17, 2021

I need to test if an AABB3 intersects OR contains a Line3, so I wrote this patch

/// Tests if the AABB contains OR intersects a line.
fn intersects(&self, aabb: &Aabb3<S>) -> bool {...

This seems to be in line with how AABB3.intersects(AABB3) and Sphere3.intersects(Sphere3) works:

let aabb = Aabb3::new(Point3::new(0., 0., 0.), Point3::new(10., 10., 10.));
let entirely_inside = Aabb3::new(Point3::new(4., 4., 4.), Point3::new(6., 6., 6.));
let partly_outside = Aabb3::new(Point3::new(4., 4., 4.), Point3::new(6., 6., 60.));
assert!(aabb.intersects(&entirely_inside));
assert!(aabb.intersects(&partly_outside));

let sphere = Sphere {center: Point3::new(0f64, 0f64, 0f64),radius: 1f64,};
let entirely_inside = Sphere {center: Point3::new(0.5f64, 0f64, 0f64),radius: 0.001f64,};
let partly_outside = Sphere {center: Point3::new(0.5f64, 0f64, 0f64),radius: 1f64,};
assert!(sphere.intersects(&entirely_inside));
assert!(sphere.intersects(&partly_outside));

But does a line, entirely contained within an AABB, really intersect it? I would have difficulties pointing at any intersection point.
If it does, maybe this should be clearly documented in the trait?
Or maybe I should have implement some other trait?

I guess one could interpret intersection as "if anything occupies any part of the volume(for 3d) or area(for 2d) of an AABB, it's a hit"

Anyhow, could someone check if my patch is something you want include (or give some feedback)? I'd be happy to make a PR.

P. S. There is an issue I've noticed: If the Line skims the surface of the AABB it will not register as an intersection. But the same is true for Ray.intersects(AABB) tests (#27).

P.S.S In the process I implemented Try_From(Line)->Ray (Euclidian). Turns out I could not use it, but it is still in there.

@kvark kvark added the question label Sep 17, 2021
@eadf eadf changed the title Intersection vs contains semantics Line3.intersects(AABB3) Sep 18, 2021
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

2 participants