Shortest Distance Between Two Lines in N dimensions
by Alexander Brodsky
26 Oct 2010
(Updated 01 Apr 2011)
Function calculates shortest distance between two lines
presented by two points for each line.
|
Watch this File
|
| File Information |
| Description |
Function uses algorithm from Dan Sunday internet site
http://softsurfer.com/Archive/algorithm_0106/algorithm_0106.htm#dist3D_Segment_to_Segment
L1, L2 includes two points in matrix of 2*n
where n are dimensions (3 in 3D).
d - shortest distance between two lines
Pc,Qc - points where exists shortest distance d
EXAMPLE:
L1=rand(2,3);
L2=rand(2,3);
[d Pc Qc]=distBW2lines(L1,L2)
Functions of lines L1,L2 and shortest distance line
can be plotted in 3d or with minor change in 2D by
removing comments sign from code at the end of the file.
In some cases points Pc,Qc will not displayed accurately on line.
Just change value of par parameter according to point.
Programmed by Alexander Brodsky
newshurik at yahoo.com |
| Acknowledgements |
This file inspired
Shortest Distance Between Two Line Segments.
|
| MATLAB release |
MATLAB 7.10 (R2010a)
|
|
Tags for This File
|
| Everyone's Tags |
|
| Tags I've Applied |
|
| Add New Tags |
Please login to tag files.
|
| Updates |
| 01 Apr 2011 |
1. Distance value was corrected (thanks to Guy)
2. Dot function was changed by matrix multiplication for speeding the script |
|
Contact us