```Path: news.mathworks.com!not-for-mail
From: Alan Weiss <aweiss@mathworks.com>
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\$1@fred.mathworks.com>
References: <gp8je2\$80b\$1@fred.mathworks.com>
NNTP-Posting-Host: weissa.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1236785617 8361 172.31.57.119 (11 Mar 2009 15:33:37 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 11 Mar 2009 15:33:37 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.19 (Windows/20081209)
Xref: news.mathworks.com comp.soft-sys.matlab:524077

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