From: Alan Weiss <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Intersection of two straight lines in 3D space
Date: Wed, 11 Mar 2009 11:33:37 -0400
Organization: The MathWorks, Inc.
Lines: 26
Message-ID: <gp8lkh$859$>
References: <gp8je2$80b$>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: 1236785617 8361 (11 Mar 2009 15:33:37 GMT)
NNTP-Posting-Date: Wed, 11 Mar 2009 15:33:37 +0000 (UTC)
User-Agent: Thunderbird (Windows/20081209)
In-Reply-To: <gp8je2$80b$>
Xref: comp.soft-sys.matlab:524077

[2.5 2.5 2.5] (you can do this one in your head)

Represent each line as A1 + t*(A2 - A1) and B1 + s*(B2 - B1).
t = s = 2.5 gets the answer

In general, there is no solution to 2 lines in 3-space, and you could 
instead find the point where the sum of squares is minimized. Represent 
the sum in terms of t and s as above, differentiate, set to zero, voila!

Alan Weiss
MATLAB mathematical toolbox documentation

James wrote:
> Hello,
> I've got two lines in 3D space, each represented by two points (of x,y,z coords) such as:
> A1=[0 0 0];
> A2=[5 5 5];
> B1=[0 5 5];
> B2=[5 0 0];
> I would like to be able to calculate the (x,y,z) coordinates at which they intersect. With my own beginners Matlab knowledge and feeble grasp of maths, I have been able to calculate something similar in 2D (by calculating line equations in the form y=mx+c and then solving) but I am stuck at trying to do this in 3D. 
> Any help would be greatly appreciated, this is a real road block in my work and it is slowly driving me potty!