Re: Plane fit [message #39149 is a reply to message #39094] |
Tue, 20 April 2004 08:55   |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
Hi Steve,
"Steve" <Steve.Morris@libero.it> wrote in message
news:606669c3.0404200355.71209718@posting.google.com...
> Hi!
> I was wondering if there is any function/routine to compute a 2
> dimensional fit (i.e. a surface) that fits a series of points spread
> in 3-dim space.
> Cheers,
> S.
This is what I use, based on Craig Markwardt's excellent MPFIT routines
(you'll need at least mpfit.pro and mpfit2dfun.pro from
http://cow.physics.wisc.edu/~craigm/idl/fitting.html):
;----------------------------------------
FUNCTION Plane2DFunction, x, y, parms, dParms
; parms define a plane: [c00, c01, c10] (1st-order polynomial in 2
vbles)
Return, parms[0] + parms[1]*x + parms[2]*y
END
;----------------------------------------
;; Then, if data is a (3, n) array of xyz points...
fitParms = MPFIT2DFUN('Plane2DFunction', $
data[0, *], data[1, *], data[2, *], $
0D, $ ; Error measure, ignored with Weights...
[Mean(data[2, *]), 0D, 0D], $ ; Estimate
Weights=Replicate(1D, nPts), /Quiet)
;; Then, for any x and y values...
fitZ = Plane2DFunction(x, y, fitParms)
;-----------------------------------------
Hope this helps!
Cheers,
--
-Dick
Dick Jackson / dick@d-jackson.com
D-Jackson Software Consulting / http://www.d-jackson.com
Calgary, Alberta, Canada / +1-403-242-7398 / Fax: 241-7392
|
|
|