• Advertisement
Sign in to follow this  

Finding the nearest point on a box for a line

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement