# Projection of a point onto a line in 3-space.

1. Jan 12, 2012

### Tynged

I am working on an implementation of the Gilbert–Johnson–Keerthi distance algorithm and am having difficulty with some of the more general math involved.

I am able to find the projection of a point onto a plane because I'm given at least three points on the plane and the point that is to be projected. I can form two vectors given the three points on the plane and take the cross product of those two vectors to create a vector orthogonal to both vectors in addition to the plane.

I am unsure how to do this when projecting a point onto a line, however. I know two points on the line and the point that is to be projected. There are an infinite number of vectors perpendicular to this line, but the one that also goes through the given point not on the line should be the vector I'm looking for.

I'd also like to note that I am using a single data structure to represent both points and vectors in 3-space. A structure containing the data {0, 0, 0} could represent a point at the origin or a vector with zero magnitude. A structure containing the data {3,4,0} could represent a point where x=3, y=4, and z=0 or it could represent a vector whose tail is at the origin and whose head is at the point where x=3, y=4, and z=0. In the implementation I am using, vector tails are always placed at the origin, and vector heads are placed at the given x,y,z coordinate. This makes it a little more difficult to think about the problem, for me at least.

2. Jan 12, 2012

### AlephZero

If you have a line AB and a point P, this is a 2D problem (on a plane with an arbitrary orientation in 3D space, of course).

The point of intersection Q is a linear interpolation between the points A and B. So Q = A + s(B-A) for some value of s.

Then you have the dot-product AB . PQ = 0 to find s.

3. Jan 13, 2012

### HallsofIvy

Assuming you mean orthogonal projection, the simplest way to find the projection of point $P= (x_0, y_0, z_0)$ on line l given by parametric equations $x= at+ b$, $y= ct+ d$, $z= et+ f$, is to determine to plane perpendicular to l that contains P- that will be, of course, a(x-x_0)+ c(y-y_0)+ e(z- z_0)= 0- and determine where the given line crosses that plane.