Ray.IntersectSphere returns a hit for NaN values
See original GitHub issueDescription of the problem
If the sphere in Ray.IntersectSphere has any null or NaN values, the function will return a modified target
with its values set to NaN rather than returning null as expected for a non-intersection. When used in raycasting the result is that an object with invalid values is permanently added to the top of the list of current intersections.
The culprit is:
https://github.com/mrdoob/three.js/blob/dev/src/math/Ray.js#L266
As it is using a truthy condition to inditcate a miss. Reversing the comparison to:
if ( !(d2 <= radius2) ) return null;
Would instead return null if either value is invalid.
Three.js version
- Dev
- r93
Browser
- All of them
- Chrome
- Firefox
- Internet Explorer
OS
- All of them
- Windows
- macOS
- Linux
- Android
- iOS
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Ray intersection with INFINITE number of spheres
My problem is that I have an infinite number of spheres that lie on a grid, with constant sized steps between them. I...
Read more >Fast Ray Sphere collision code [closed]
UPDATE: The following sample returns the interval T along the ray and the point of intersection Q. You can calculate the normal of...
Read more >Precision Improvements for Ray/Sphere Intersection
To find the intersection between the sphere and the ray we can replace P by ... These t-values can be plugged into the...
Read more >A Minimal Ray-Tracer: Rendering Spheres - Scratchapixel
Once we know the value for t0 computing the position of the intersection or hit point is straightforward. We just need to use...
Read more >raycast/sphere.cpp at master - GitHub
The function should return the parameter value for the intersection, ... float intersect_sphere(Point o, Vector ray, Spheres *sph, Point* hit).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
three.js expects valid data – not null, NaN, or missing; it is up to your application layer to ensure that.
If three.js accommodated invalid data in this method, it would have to do so in every method.
Instanced geometry is very flexible, and it may be difficult to support instanced-raycasting in general, but a three.js example in which that is done would be awesome, if you are interested. 😃
Correct. Closing the issue since it’s an app related issue.