# Ray Box intersection

**URL:** https://discourse.vtk.org/t/ray-box-intersection/15243
**Category:** Support
**Created:** [February 5, 2025, 9:33am UTC](https://discourse.vtk.org/t/ray-box-intersection/15243 "2025-02-05T09:33:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ferdymercury](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ferdymercury/32/3870_2.png) [@ferdymercury](https://discourse.vtk.org/u/ferdymercury)
#### Post date: [February 5, 2025, 9:33am UTC](https://discourse.vtk.org/t/ray-box-intersection/15243/1 "2025-02-05T09:33:41Z")

</div>

Dear experts,  
I wanted to ask if there is an optimized code within VTK that returns the 1D coordinate of the intersection of a directional ray within a box, with the box itself.  
Something like explained here: [https://people.csail.mit.edu/amy/papers/box-jgt.pdf](https://people.csail.mit.edu/amy/papers/box-jgt.pdf)

I took a look at vtkBox::IntersectWithLine but at first glance it seems suboptimal for my application, since it returns two intersection values (ray is bidirectional there).

Thanks in advance!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 3, 2025, 10:50pm UTC](https://discourse.vtk.org/t/ray-box-intersection/15243/2 "2025-03-03T22:50:28Z")

</div>

@dcthomp Is there anything like this in VTK?

---

<div class="post-metadata">

### Author: ![dcthomp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dcthomp/32/60_2.png) [@dcthomp](https://discourse.vtk.org/u/dcthomp)
#### Post date: [March 4, 2025, 7:05am UTC](https://discourse.vtk.org/t/ray-box-intersection/15243/3 "2025-03-04T07:05:06Z")

</div>

Have you considered [vtkBox::IntersectBox](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Common/DataModel/vtkBox.h#L88) (rather than IntersectWithLine)?

---

<div class="post-metadata">

### Author: ![ferdymercury](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ferdymercury/32/3870_2.png) [@ferdymercury](https://discourse.vtk.org/u/ferdymercury)
#### Post date: [March 4, 2025, 8:39am UTC](https://discourse.vtk.org/t/ray-box-intersection/15243/4 "2025-03-04T08:39:54Z")

</div>

Thanks a lot for the reply, that function seems closer to what I was looking for.  
However I ended up with an own implementation, since in the case the starting point is “inside” the bounding box surface, I want the algorithm to look for the distance to the next intersection.
