// elltst.cpp -- incremental scan conversion of tilted ellipse // (C) 2002, C. Bond. All rights reserved. // #include #include // // scan conversion of X-Y plot of tilted ellipse. // // The parametric equations are: // // x = a cos(theta)cos(phi) - b sin(theta)sin(phi) // y = a cos(theta)sin(phi) + b sin(theta)cos(phi) // // where 'theta' is the parameter, 0 < theta < 2pi, 'phi' is the // tilt angle of the ellipse, 'a' is the major axis, and 'b' is // the minor axis. // int main() { double phi,theta,a,b,x,y,dx,dy,sn,cs,s,c; // initialize major axis, minor axis, tilt angle a = 40.0; // major axis b = 30.0; // minor axis phi = 3.14159265359/6.0; // tilt angle: 30 degrees sn = sin(phi); cs = cos(phi); // initialize parameter theta = 0.0; // main loop while (theta <= 6.28318530718) { s = sin(theta); c = cos(theta); x = a*c*cs-b*s*sn; y = a*c*sn+b*s*cs; cout << "(" << floor(x+0.5) << ", " << floor(y+0.5) << ")" << endl; dx = fabs(a*s*cs+b*c*sn); dy = fabs(a*s*sn-b*c*cs); if (dx > dy) theta += 1.0/dx; else theta += 1.0/dy; } return 0; }