Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Point closest to a set four of lines in 3D

Given 4 lines in 3D (represented as a couple of points), I want to find the point in space which minimizes the sum of distances between this point and every line.

I'm trying to find a way to formulate this as a Least Squares Problem, but I'm not quite sure as to how I should. I'm currently trying to use the definition of distance provided at: http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html

Any ideas?

like image 813
Prateek Rungta Avatar asked Nov 15 '22 00:11

Prateek Rungta


1 Answers

I made a program in Mathematica for calculating the point coordinates. The result is a large algebraic formula. I uploaded it to ideone for you.

Here is the program, in case you have Mathematica at hand:

(*Load package*)
Needs["VectorAnalysis`"]
(*Define four lines, by specifying 2 points in each one*)
Table[p[i, j] = {x[i, j], y[i, j], z[i, j]}, {i, 4}, {j, 2}];

(*Define the target point*)
p0 = {x0, y0, z0};

(*Define a Norm function // using Std norm squared here*)
norm[a_] := a[[1]]^2 + a[[2]]^2 + a[[3]]^2

(*Define a function for the distance from line i to point v
used http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html (11) *)
d[i_, v_] :=  norm[Cross[(v - p[i, 1]), (v - p[i, 2])]]/norm[p[i, 2] - p[i, 1]]

(*Define a function for the sum of distances*)
dt[p_] := Sum[d[i, p], {i, 4}]

(*Now take the gradient, and Solve for Gradient == 0*)
s = Solve[Grad[dt[p0], Cartesian[x0, y0, z0]] == 0, {x0, y0, z0}]

(* Result tooooo long. Here you have it for downloading
http://ideone.com/XwbJu *)  

RESULT

like image 74
Dr. belisarius Avatar answered Nov 24 '22 00:11

Dr. belisarius