Re: How do I fit a line through three points in space?

From: Valeri Astanoff (astanoff_at_yahoo.fr)
Date: 09/17/04


Date: 17 Sep 2004 09:26:47 -0700

redb@mail2pilot.com (Red B.) wrote in message news:<3e8e907f.0409170103.74247189@posting.google.com>...
> Hi all!
>
> How do I go about fitting a straight line (vector) through three
> points in space? Each of the three points is given by three
> coordinates (x,y,z) that are measured with some uncertainty.
> The textbooks I have all discuss using the method of least squares for
> fitting a straight line through a number of (x,y) points in a plane
> but I need a method that works in three dimensions.
>
> Although this is probably a trivial problem for you mathematicians I
> would appreciate any help you can offer.
>
> /Red B.

 This is a way to find an acceptable solution :
 Let the line pass thru the center of gravity and
 then compare the 6 directions defined by the cg
 and one point or parallel with two points.
      
 A model in mathematica :

lineFit[OM1_,OM2_,OM3_]:=
    Module[{},
      norm[vec_]:=Sqrt[vec.vec];
      OG=(OM1+OM2+OM3)/3;
      v[1]=OM1-OG;
      v[2]=OM2-OG;
      v[3]=OM3-OG;
      v[4]=OM2-OM1;
      v[5]=OM3-OM2;
      v[6]=OM1-OM3;
      d[i_]:=norm[Cross[v[i],(OM1-OG)]]/norm[v[i]]
          +norm[Cross[v[i],(OM2-OG)]]/norm[v[i]]
          +norm[Cross[v[i],(OM3-OG)]]/norm[v[i]] ;
      res={v[#],d[#]}&/@{1,2,3,4,5,6} ;
      Sort[res,Last[#1]<Last[#2]&]
      ];

example :
lineFit[{1.,1.,1.},{5.,1.,2.},{3.,5.,3.}]

{{{0., 2.66666, 1.}, 4.10812}, {{-2., -1., -1.}, 4.49407},
  {{-2., -4., -2.}, 4.77648}, {{2., -1.33333, 0.}, 4.86747},
  {{-2., 4., 1.}, 5.10627}, {{4., 0., 1.}, 5.6753}}

points aligned :
lineFit[{1.,1.,1.},{2.,2.,2.},{4.,4.,4.}]

{{{-3., -3., -3.}, 0.}, {{2., 2., 2.}, 0.}, {{1., 1., 1.}, 0.},
  {{ 1.66666, 1.66666, 1.66666}, 0.},
  {{-0.33333, -0.33333, -0.33333}, 0.},
  {{-1.33333, -1.33333, -1.33333}, 0.}}

hth

V.Astanoff



Relevant Pages

  • Re: How do I fit a line through three points in space?
    ... > fitting a straight line through a number of points in a plane ... > Although this is probably a trivial problem for you mathematicians I ... With two coordinates it's just linear regression, ...
    (sci.math.num-analysis)
  • Re: Lens cleaning/new drive fitter?
    ... i replacement mine using this online guide, just as easy as fitting a new ... drive into a pc quite straight forward ... if your not that brave i am sure someone will suggest someone who can do ...
    (uk.games.video.xbox)
  • Re: linear fitting: different errors on X data and Y data
    ... I'm looking for a software that can perform linear fitting with weights ... R. J. Adcock, "Note on the method of least squares," The Analyst (Des ... "A better least-squares method when both variables have ... straight lines or more complicated functions. ...
    (sci.physics)
  • How do I fit a line through three points in space?
    ... How do I go about fitting a straight line through three ... Although this is probably a trivial problem for you mathematicians I ...
    (sci.math.num-analysis)
  • Re: A SIMPLE CHALLENGE that you great Mathematicians wont answer...
    ... But that is the problem - infinitisation of the finite in all ... The mathematicians here aggressively say that mathematics and reality ... the axes themselves must be 'straight lines' to ... Why does the Pythagoras Theorem use 'squares'...? ...
    (sci.math)