Sign in to follow this  
riff

Finding the nearest point on a box for a line

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this