# Finding the nearest point on a box for a line

This topic is 3817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, Say you have a box with origin (0,0,0) and a line described by two angles, A and B which also starts at the origin. How would you find the point on the box at which the line emerges? I'm basically trying to attach boxes to each other using just two angles to specify where the new box emerges. Thanks for any help :)

##### Share on other sites
Your box's surface is made up of 6 rectangular plane segments. For each of these, you can find its equation, compute the intersection with the equation of the line and throw out the intersection points that don't actually lie on the box's surface. Since your solid is convex, this is equivalent to just taking the minimum distance intersection point from the origin.

Your description is a bit ambiguous, but I'll assume you have an axis-aligned box with corners at (0,0,0) and (x,y,z), and a line with equation (x,y,z)=(t cos phi cos theta, t cos phi sin theta, t sin phi). For simplicity, I'll assume the line is oriented in the positive x/y/z directions so we only have three planes to worry about:

t1 = x / (cos phi cos theta)
t2 = y / (cos phi sin theta)
t3 = z / (sin phi)
t = min(t1, t2, t3)

Then you just substitute t into the equation of your line to get XYZ coordinates.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 11
• 13
• 91
• 11
• 10
• ### Forum Statistics

• Total Topics
632973
• Total Posts
3009622
• ### Who's Online (See full list)

There are no registered users currently online

×