How can I find the line equations corresponding to a line through two 3D points?

33 views (last 30 days)
Hi!
I have two three dimensional points (xp,yp,zp) and (xq,yq,zq). Through these points runs an infinite line. How can I find the equations to describe this line in 3D?
In other words, is it possible to find the variables a1,b1,c1,d1,a2,b2,c2,d2 in the line description: a1x + b1y + c1z = d1 a2x + b2y + c2z = d2 if you know two points p and q on the line?
Thanks!

Accepted Answer

Matt J
Matt J on 3 Jun 2014
Edited: Matt J on 3 Jun 2014
The pair of equations are not unique, but one particular selection of them can be obtained as follows, with P=[xp,yp,zp].' and Q=[xq,yq,zq].',
Aeq=null((P-Q).').'; %2x3
beq=Aeq*P; %2x1
The equations you're looking for in matrix/vector form are then Aeq*u=beq, where u=[x;y;z] is a point in 3D space.

More Answers (1)

John D'Errico
John D'Errico on 3 Jun 2014
Edited: John D'Errico on 3 Jun 2014
Using basic algebra? It helps if one knows how a line can be defined in a general number of dimensions.
If V is a vector that points along the line, then we can define the line as:
L(t) = P + V*t
Here P is a point on the line, ANY point will suffice, and t is a scalar parameter. Essentially this defines a parametric representation for the line. Assume you have two points, XP and XQ, defined as vectors:
XP = [xp,yp,zp]
XQ = [xq,yq,zq]
Then the vector V can be written as
V = XQ - XP
If you prefer, you can normalize V by dividing by the vector norm, norm(V). If you do so, then t would now have units of distance along the line. I prefer the simpler form I show above though. This way, we can choose
P = XP
so that
L(0) = XP
L(1) = XQ
Likewise, the point midway between the points XP and XQ is given as L(0.5). This parametric form of a line is a very nice one, worth remembering.
Finally, as to your question about whether it is possible to find the coefficients {a1,b1,c1,d1,a2,b2,c2,d2}, in a line description, thus:
a1x + b1y + c1z = d1
a2x + b2y + c2z = d2
Absolutely not possible, or trivially so. Well, not possible to do so uniquely.
Here you need to understand more about the geometry. (Perhaps it is time to go re-read your notes from high school? Honestly, I'm not sure anymore what they are teaching in high school with the new math these days. All of this is pretty basic geometry.)
EACH of those equations you have written describes a plane. TWO planes intersect to form a line (If they intersect at all.) However, there are INFINITELY many planes that can intersect to form any given line. So it is impossible to determine those planes uniquely, while it is also trivial to determine a pair of planes that suffice.
It turns out that a pair of planes can be defined by the null-space vectors of the vector V. Thus null(V) returns the coefficients you need, as a pair of vectors, call them U1 and U2.
Then the planes are defined by
dot(X - P,U1) = 0
dot(X - P,U2) = 0
Again, P is the point on the line we chose before. If you expand those dot products, you will get a pair of sets of plane coefficients. The constant term falls out too. So just a bit of basic algebra, since the dot product can be expanded as:
dot(X,U1) = dot(P,U1) = d1
dot(X,U2) = dot(P,U2) = d2

Categories

Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!