Re: How do I fit a line through three points in space?
From: Valeri Astanoff (astanoff_at_yahoo.fr)
Date: 09/17/04
- Next message: Layi Otolorin: "Re: zeros of a polynomial of third order"
- Previous message: C W: "Re: How to solve this PDE? (Pleaaaaaaaaaaaaase!!)"
- In reply to: Red B.: "How do I fit a line through three points in space?"
- Next in thread: anonymous: "Re: How do I fit a line through three points in space?"
- Reply: anonymous: "Re: How do I fit a line through three points in space?"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Layi Otolorin: "Re: zeros of a polynomial of third order"
- Previous message: C W: "Re: How to solve this PDE? (Pleaaaaaaaaaaaaase!!)"
- In reply to: Red B.: "How do I fit a line through three points in space?"
- Next in thread: anonymous: "Re: How do I fit a line through three points in space?"
- Reply: anonymous: "Re: How do I fit a line through three points in space?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|