#include "stdio.h" #include "stdlib.h" #include "math.h" /* Create a 2D and 3D version (surface of revolution of a Cassinian oval. Geometry is output in Vision3D text format, it should be easy to output geometry of your choice. N is the number of points along the curve M is the number of ribs in the surface of revolution When a > b only one half of the split surface is created. */ #define N 40 #define M 18 #define PI 3.141592653589793238462643 #define TWOPI 6.283185307179586476925287 typedef struct { double x,y,z; } XYZ; XYZ Eval(double,double,double,int); XYZ XRotate(XYZ,double); int main(int argc,char **argv) { int i,j,k; int thesign; double theta1,theta2; double tstart,tstop,t1,t2; XYZ p[4]; FILE *f2d,*f3d; char fname[64]; double a,b; /* Control parameters for the curve */ /* Get the input parameters */ if (argc < 3) { fprintf(stderr,"Usage: %s a b\n",argv[0]); exit(-1); } a = atof(argv[1]); b = atof(argv[2]); /* Set the bounds for the parameter t */ tstart = 0; if (a <= b) tstop = PI; else tstop = 0.5 * asin(b*b/(a*a)); /* Open the 2D geometry file */ sprintf(fname,"egg_%g_%g.2d",a,b); f2d = fopen(fname,"w"); fprintf(f2d,"2 1000 0.8 0.5 2\n0 0 0\n2 0 0\n1 0 0\n"); /* x axis */ fprintf(f2d,"2 1000 0.8 0.5 2\n0 -1 0\n0 1 0\n0 1 0\n"); /* y axis */ /* Open the 3D geometry file */ sprintf(fname,"egg_%g_%g.3d",a,b); f3d = fopen(fname,"w"); fprintf(f3d,"2 1000 0.8 0.5 2\n0 0 0\n2 0 0\n1 0 0\n"); /* x axis */ fprintf(f3d,"2 1000 0.8 0.5 2\n0 -1 0\n0 1 0\n0 1 0\n"); /* y axis */ fprintf(f3d,"2 1000 0.8 0.5 2\n0 0 -1\n0 0 1\n0 0 1\n"); /* z axis */ for (j=0;j b, -to < t < to where to = 0.5 * asin(b^2/a^2) */ XYZ Eval(double t,double a,double b,int sign) { XYZ p; double c1,c2; c1 = b*b*b*b - a*a*a*a*sin(2*t)*sin(2*t); if (c1 <= 0) /* Shouldn't happen with correct usage */ c2 = a * a * cos(2*t); else c2 = a * a * cos(2*t) + sign * sqrt(c1); p.x = cos(t) * sqrt(c2); p.y = sin(t) * sqrt(c2); p.z = 0.0; return(p); }