Line-Line Intersection (N lines, D space)

Version 1.0.0.0 (2,86 KB) von Serge
Find intersection of N lines in D-dimensional space, in least squares sense.
407 Downloads
Aktualisiert 29. Okt 2016

Lizenz anzeigen

Find intersection of N lines in D-dimensional space, in least squares sense.
X = lineXline(A,B) -line starts & ends as N*D
X = lineXline({x y..}) -lines as D long cell of starts & ends as 2*N
[X,P,R] = lineXline(..) -extra outputs
[X,P,R,x,t,l] = lineXline(..) -plot outputs
X: Intersection point, in least squares sense, as 1*D
P: Nearest point to the intersection on each line, as N*D
R: Distance from intersection to each line, as N*1
x: Intersection point X as D-long cell of coordinates {x y..}
p: Nearest points P as D-long cell of coordinates {x y..} as N*1
l: Initial lines A-to-B as D-long cell of coordinates {x y..} as 2*N

Remarks:
-Lines are assumed to be infinite in both directions.
-Finds point nearest to all lines using minimum sum of squared distances.
-For parallel lines returns an arbitrary point and a warning.
-For lines of length zero returns NaNs.
-Comments/issues/corrections email Serge: s3rg3y@hotmail.com

Example: (3 lines, 2 dimensions)
[X,P,R,x,p,l] = lineXline([0 0;3 0;0 4],[5 5;0 5;5 2]);
plot(x{:},'*k',p{:},'.k',l{:})
X2 = lineXline(l) %alternate input form, same results

Example: (2 lines, 3 dimensions)
[X,P,R,x,p,l] = lineXline(rand(2,3),rand(2,3));
plot3(x{:},'*k',p{:},'.k',l{:})

Example: (4 lines, 5 dimensions)
[X,P,R] = lineXline(rand(4,5),rand(4,5))

Zitieren als

Serge (2024). Line-Line Intersection (N lines, D space) (https://www.mathworks.com/matlabcentral/fileexchange/59805-line-line-intersection-n-lines-d-space), MATLAB Central File Exchange. Abgerufen .

Kompatibilität der MATLAB-Version
Erstellt mit R2010b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Kategorien
Mehr zu NaNs finden Sie in Help Center und MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Veröffentlicht Versionshinweise
1.0.0.0

Minor changes
Minor changes
Minor changes
Minor changes

Changed description
Minor changes
Minor changes
Minor changes
Minor changes
Minor changes
Changed 5th output, minor changes