Changeset 3105 for trunk/Ohana/src/opihi/mana/fitcontour.c
- Timestamp:
- Jan 28, 2005, 5:17:26 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/mana/fitcontour.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/mana/fitcontour.c
r3030 r3105 36 36 r = hypot (x, y); 37 37 38 /* 39 t = 2*atan2(y,x); 40 sn = sin(t); 41 cs = cos(t); 42 */ 38 /* calculate sin(2t), cos(2t) using 1/2 angle tri relationship above */ 43 39 sn1 = y / r; 44 40 cs1 = x / r; … … 63 59 gaussj (C, NTERM, B, 1); 64 60 61 /** this is somewhat weak: if the object is too elongated, Rmin can be < 0 **/ 65 62 dR = hypot (B[1][0], B[2][0]); 66 63 Rmaj = B[0][0] + dR; … … 101 98 } 102 99 100 101 /* this routine fits a single sine and cosine to the value of dr as a function of the angle around the central 102 * point, theta. this is NOT an exact fit, an is increasingly in error for more eccentric ellipses. however, 103 * it does a reasonable job of approximating the value of the major and minor axes, and it gets the angle of 104 * orientation right at well. We then assume the values of major and minor axis and angle are correct to get 105 * the parameters for the elliptical gaussian fit: 106 107 z = (x^2) / (2 Rx^2) + (y^2) / (2 Ry^2) + Rxy x y 108 109 the functions above give the correct relationship between these: 110 111 R1 = SQ(Rmaj) + SQ(Rmin); 112 R2 = SQ(Rmaj) - SQ(Rmin); 113 R3 = Rmaj*Rmin; 114 115 Rx = R3 / sqrt (R1 - R2*cs); 116 Ry = R3 / sqrt (R1 + R2*cs); 117 Rxy = -sn*R2 / SQ(R3); 118 119 to derive these relationships, write the equation for an ellipse with major axis in the x-dir and minor in 120 the y-dir: 121 122 z = (x^2) / (2 Rmaj^2) + (y^2) / (2 Rmin^2) 123 124 apply the rotation matrix: 125 126 (x)' = (cos, -sin)(x,y) 127 (y)' = (sin, +cos)(x,y) (modulo the sign on the sine) 128 129 then group the x^2 terms, the y^2 terms, and the xy terms to find the three coeffs. 130 131 NOTE: I spent a while having trouble deriving this from the polar form of an ellipse: 132 133 x = Rmaj*cos(theta) 134 y = Rmin*sin(theta) 135 136 it turns out that 'theta' above is NOT the angle (0,1)-(0,0)-(x,y). rather, it should be viewed as a 137 paraterization of the ellipse. 138 139 */
Note:
See TracChangeset
for help on using the changeset viewer.
