Navigation 
 Home 
 Search 
 Site map 

 Contact Graeme 
 Home 
 Email 
 Twitter

 Skip Navigation LinksMath Help > Geometry > Points and Lines > Lines in 3D

Equation of a line in three dimensions

As you may know, three independent linear equations in three variables (which I will call x, y, and z to represent the three axes) has a single solution; they represent a point.  If you are given only two independent linear equations in these three variables, they will have infinitely many solutions, but what is the "shape" of those solutions?  To understand the shape, think about "pinning down" one of the variables, say, x.  When x has a specific value, say, x=c, then you can solve for y and z.  In other words, the plane represented by x=c intersects the shape in one point.  This is true also for all the planes parallel to x=c.  What shape intersects all parallel planes in one point each?  A line, of course.  And finally, if you have only one linear equation in three variables, this represents a plane.  So here is the summary:

Number of
independent linear
equations in
three variables

Shape of the
solution of
the equations

3

point

2 line
1 plane
0 space

Finding the vector equation of a line

If you are given the equations of a line as

(x-x0)/x1 = (y-y0)/y1 = (z-z0)/z1

Then you can make a parameter, t, equal to each of these, as

(x-x0)/x1 = (y-y0)/y1 = (z-z0)/z1 = t

Then this is easily converted to the vector equation

( x ) ( x0 ) ( x1 )
r y  =  y0  + t y1
z z0 z1

If you are given a pair of equations in three variables

ax + by + cz = d
fx + gy + hz = j

Then you should eliminate one of the variables, say, z, and let that be your parameter.  This gives you

t = z, and

x = ( (dg-jb) + t(bh-cg) ) / (ag-bf)
y = (-(df-ja) + t(cf-ah) ) / (ag-bf)
z = (      0  + t(ag-bf) ) / (ag-bf)

I would love to find a more "parallel" way of converting a pair of linear equations into a set of parametric equations.  Email me!  . . . . . . 

Finding the distance between two lines

Expressing the two lines, L1 and L2, in parametric form where r,a,b,c,d are vectors, and s,t are scalar parameters,

(L1)    r = a + bs,
(L2)    r = c + dt,

then the distance between the two lines is given by

g = (a-c)·(b×d) / |b×d|

Why does this formula work?

Recall that the dot product of two vectors can be viewed geometrically as the length of the projection of the first vector onto the line represented by the second vector times the length of the second vector.  This is particularly useful when the second vector is a unit vector.  In this case, if you extend the second vector and think of it as a "base", then rays of light falling perpendicular to the base will pass through the first vector, and cast a shadow onto the base whose length is the dot product of the two vectors.  Also, recall that the cross product of two vectors a,b is a vector whose direction is orthogonal to both a and b.

Now picture lines L1 and L2 as having "directions" represented respectively by vectors b and d.  The direction that is orthogonal to both b and d is given by b×d.  The unit vector, u, in this direction is u=b×d/|b×d|.  Now orient your perspective so that L1 and L2 lie in parallel planes P1 and P2.  The distance between the lines, then, is the distances between the planes, measured in a direction normal to the planes, i.e. measured in the direction given by vector u, which is perpendicular to L1 and L2 and thus normal to the planes.

Now, from the parametric equations of the two lines, we know that vectors a and c can be construed (using the point - vector duality) as represent points on lines L1 and L2.  The difference between them (a-c) is a vector giving the distance between the planes P1 and P2 in some direction, but not necessarily in a direction orthogonal to the planes.  So we have a vector (a-c) whose length in some direction is the distance between the planes, and we have another vector, u=b×d/|b×d|, whose direction is normal to both planes.  Now, we just need to cast the shadow of (a-c) onto the line containing u, and find its length!  Of course, the dot product does that job for us.

Finding the closest points

Now you might also want to find the particular points on L1 and L2 where the lines come closest to each other.  For that, let line L3 be the projection of line L1 onto plane P2.  We have already calculated

u = (b×d) / |b×d|, the vector giving the direction from a point on P1 toward its shadow on P2

and

g = (a-c)·u, the orthogonal distance from P1 to P2.

Now,

(L3)    r = g u + a + bs, and as a reminder,
(L2)    r = c + dt,

So now we can solve (g u + a) + bs  = c + dt for s,t to find r.  We can use any two components of the vectors to make two linear equations in the two variables s,t in order to solve the equation.

Internet references

Related pages in this website

Finding the distance between a line and a point.

Vectors, and their dot product, cross product.

 

The webmaster and author of this Math Help site is Graeme McRae.