Can you elaborate more on what is not working with your code. There are a
lot of algorithms for axis aligned bounding box and ray intersections. This
<http://www.realtimerendering.com/intersections.html> is a good resource
for such algorithms.
Also, I see that your function is either returning `None` or some float
value (t_min). Usually, the intersection algorithms return a boolean -
`True` for an intersection, `False` otherwise.
The algorithm you have posted seems alright to me except that you need to
return a bool. Probably this should be -
def box_aabb_intersect(bbox_min, bbox_max, ray, direction):
t1 = (bbox_min.x - ray.x) * direction.x
t2 = (bbox_max.x - ray.x) * direction.x
t3 = (bbox_min.y - ray.y) * direction.y
t4 = (bbox_max.y - ray.y) * direction.y
t5 = (bbox_min.z - ray.z) * direction.z
t6 = (bbox_max.z - ray.z) * direction.z
t_min = max(max(min(t1, t2), min(t3, t4)), min(t5, t6))
t_max = min(min(max(t1, t2), max(t3, t4)), max(t5, t6))
return t_max >= t_min
On Wed, May 17, 2017 at 4:50 PM, Rémi Deletrain <[email protected]>
wrote:
> Hello everybody,
> I try to make a code find an intersection between a ray and a box. I read
> a lot of thing on the internet and one of the best code I could find is
> this one.
>
> def box_aabb_intersect(bbox_min, bbox_max, ray, direction):
>
> t1 = (bbox_min.x - ray.x) * direction.x
> t2 = (bbox_max.x - ray.x) * direction.x
> t3 = (bbox_min.y - ray.y) * direction.y
> t4 = (bbox_max.y - ray.y) * direction.y
> t5 = (bbox_min.z - ray.z) * direction.z
> t6 = (bbox_max.z - ray.z) * direction.z
>
> t_min = max(max(min(t1, t2), min(t3, t4)), min(t5, t6))
> t_max = min(min(max(t1, t2), max(t3, t4)), max(t5, t6))
>
> if t_max < 0.0 or t_min > t_max:
> return
>
> return t_min
>
>
> Everyone says it works but I can not make it work at home. Does someone
> have an idea?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/18ab0a86-841b-4390-9999-
> b23b51665012%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/18ab0a86-841b-4390-9999-b23b51665012%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMSNkw8jihfOEOR1oVFtgT70tmUdGE8swi161vqvuj9E4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.