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

Raycasts miss exact matches on boxes #7

Open
io7m opened this issue May 16, 2017 · 6 comments
Open

Raycasts miss exact matches on boxes #7

io7m opened this issue May 16, 2017 · 6 comments
Assignees
Labels

Comments

@io7m
Copy link
Member

io7m commented May 16, 2017

For example:

A box b is placed at (32, 32) of size (64, 64).

A ray is cast from (16, 32) to (256, 32). The ray should intersect b because it passes through 32 on the Y axis, and that's the minimum Y value of b. However, the current implementation misses the intersection.

@io7m io7m added the bug label May 16, 2017
@io7m io7m self-assigned this May 16, 2017
@io7m
Copy link
Member Author

io7m commented May 16, 2017

This appears to be a bug in the calculation of the inverse ray vector. The problem is that given a ray like the above: (16, 32) with direction (1, 0), the inverse vector turns out to be (1, Infinity), which is definitely wrong!

@io7m
Copy link
Member Author

io7m commented May 16, 2017

No, this is actually an expected property of the rays. See: https://tavianator.com/fast-branchless-raybounding-box-intersections/

@io7m
Copy link
Member Author

io7m commented May 16, 2017

This is actually caused by NaN values appearing in the computation. Covered here: https://tavianator.com/fast-branchless-raybounding-box-intersections-part-2-nans/

@io7m
Copy link
Member Author

io7m commented May 16, 2017

Waiting to hear from the author about whether or not anything can be done about this. I can't work it out from the second part of the article.

@tavianator
Copy link

I cover this in my latest post: https://tavianator.com/2022/ray_box_boundary.html. TLDR:

-        tmin = max(min(t1, t2), tmin);
-        tmax = min(max(t1, t2), tmax);
+        tmin = min(max(t1, tmin), max(t2, tmin));
+        tmax = max(min(t1, tmax), min(t2, tmax));
...
-    return tmin < tmax;
+    return tmin <= tmax;

@io7m
Copy link
Member Author

io7m commented Aug 14, 2023

Ah, thank you!

Sorry for the ridiculous delay in replying. I had no idea this had even been posted (I get far too many GitHub notifications for any human to deal with!). 🙂

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