Fitting Problem with line in 3D-space
![](https://secure.gravatar.com/avatar/a8bbbf786158b7ab1756762f19327cee.jpg?s=120&d=mm&r=g)
Hello, I am trying to get an axis of a cylinder in 3D-space using the leastsq method. My modell-equation is: \vec u \times (\vec r - \vec r_0) = \vec 0 u ... the direction vector r ... the independent vector r_0 ... one position vector on the line Can somebody tell me how to construct the functions leastsq is need? With simple function like y=x*... its very simple ... but not with that line Greetings
![](https://secure.gravatar.com/avatar/da3a0a1942fbdc5ee9a9b8115ac5dae7.jpg?s=120&d=mm&r=g)
Sat, 08 Nov 2008 03:53:39 +0100, Charles Monty Burns wrote:
Hello,
I am trying to get an axis of a cylinder in 3D-space using the leastsq method.
My modell-equation is:
\vec u \times (\vec r - \vec r_0) = \vec 0
u ... the direction vector r ... the independent vector r_0 ... one position vector on the line
Can somebody tell me how to construct the functions leastsq is need?
With simple function like y=x*... its very simple ... but not with that line
Like this, for example: ----------------------------------------- from scipy.optimize import leastsq import numpy as np points = np.loadtxt('points.dat') # data file with 3 columns def params(p): return p[:3]/np.linalg.norm(p[:3]), p[3:] def model(p): u, v0 = params(p) return np.cross(points - v0, u).ravel() result, ier = leastsq(model, [1, 0, 0, 0, 0, 0]) u, v0 = params(result) print u print v0 ----------------------------------------- -- Pauli Virtanen
![](https://secure.gravatar.com/avatar/a8bbbf786158b7ab1756762f19327cee.jpg?s=120&d=mm&r=g)
Tanks for your replay. Can you test your code with that points http://pastebin.mozilla.org/570655 . The result should be the direction vector (0, 0, 1). I construct this points with direction vector on z-axis. Greetings On Sat, Nov 8, 2008 at 1:59 PM, Pauli Virtanen <pav@iki.fi> wrote:
Sat, 08 Nov 2008 03:53:39 +0100, Charles Monty Burns wrote:
Hello,
I am trying to get an axis of a cylinder in 3D-space using the leastsq method.
My modell-equation is:
\vec u \times (\vec r - \vec r_0) = \vec 0
u ... the direction vector r ... the independent vector r_0 ... one position vector on the line
Can somebody tell me how to construct the functions leastsq is need?
With simple function like y=x*... its very simple ... but not with that line
Like this, for example:
----------------------------------------- from scipy.optimize import leastsq import numpy as np
points = np.loadtxt('points.dat') # data file with 3 columns
def params(p): return p[:3]/np.linalg.norm(p[:3]), p[3:]
def model(p): u, v0 = params(p) return np.cross(points - v0, u).ravel()
result, ier = leastsq(model, [1, 0, 0, 0, 0, 0]) u, v0 = params(result)
print u print v0 -----------------------------------------
-- Pauli Virtanen
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
participants (2)
-
Charles Monty Burns
-
Pauli Virtanen