Changeset 9768 for trunk/psLib/src/math/psEllipse.c
- Timestamp:
- Oct 28, 2006, 10:12:11 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psEllipse.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psEllipse.c
r7766 r9768 20 20 } 21 21 22 // ellipse rotation (major, minor, theta) -> (sx, sy, sxy) 22 23 psEllipseShape psEllipseAxesToShape(psEllipseAxes axes) 23 24 { 24 25 psEllipseShape shape; 25 26 26 double r1 = 1.0 / PS_SQR(axes.major) + 1.0 / PS_SQR(axes.minor);27 double r2 = 1.0 / PS_SQR(axes.major) - 1.0 / PS_SQR(axes.minor);27 double f1 = 1.0 / PS_SQR(axes.major) + 1.0 / PS_SQR(axes.minor); 28 double f2 = 1.0 / PS_SQR(axes.major) - 1.0 / PS_SQR(axes.minor); 28 29 29 double sxr = r1 + r2*cos(2*axes.theta);30 double syr = r1 - r2*cos(2*axes.theta);30 double sxr = 0.5*f1 + 0.5*f2*cos(2*axes.theta); 31 double syr = 0.5*f1 - 0.5*f2*cos(2*axes.theta); 31 32 32 33 shape.sx = 1.0 / sqrt(sxr); 33 34 shape.sy = 1.0 / sqrt(syr); 34 shape.sxy = r2*sin(2*axes.theta);35 shape.sxy = 0.5*r2*sin(2*axes.theta); 35 36 36 37 return shape; 37 38 } 38 39 40 // ellipse derotation (sx, sy, sxy) -> (major, minor, theta) 39 41 psEllipseAxes psEllipseShapeToAxes(psEllipseShape shape) 40 42 { … … 43 45 double f1 = 1.0 / PS_SQR(shape.sx) + 1.0 / PS_SQR(shape.sy); 44 46 double f2 = 1.0 / PS_SQR(shape.sx) - 1.0 / PS_SQR(shape.sy); 47 double f3 = PS_SQR(f2) + 4*PS_SQR(shape.sxy); 45 48 46 // force the axis ratio to be less than 10 47 double r1 = 0.5*0.95*sqrt (PS_SQR(f1) - PS_SQR(f2)); 48 49 shape.sxy = PS_MIN(PS_MAX(shape.sxy, -r1), r1); 50 51 axes.theta = atan2 (-2.0*shape.sxy, f2) / 2.0; 52 53 double Ar = 0.25*f1 + 0.25*sqrt(PS_SQR(f2) + 4*PS_SQR(shape.sxy)); 54 double Br = 0.25*f1 - 0.25*sqrt(PS_SQR(f2) + 4*PS_SQR(shape.sxy)); 55 56 axes.minor = 1.0 / sqrt (Ar); 57 axes.major = 1.0 / sqrt (Br); 49 axes.theta = 0.5 * atan2 (-2.0*shape.sxy, f2) / 2.0; 50 axes.major = sqrt (2.0 / (f1 - f3)); 51 axes.minor = sqrt (2.0 / (f1 + f3)); 58 52 59 53 return axes; 60 54 } 55 56 // XXX keep this construction? 57 // force the axis ratio to be less than 10 58 // double r1 = 0.5*0.95*sqrt (PS_SQR(f1) - PS_SQR(f2));
Note:
See TracChangeset
for help on using the changeset viewer.
