/* metacircle morphing by using Bezier Clipping by T.N '97 11/17 modified on 97' 11/15 */ import java.applet.Applet; import java.awt.*; import java.io.*; /* ******** class Curve3 : 3D Bezier curve ********************: */ class Curve3 { public Point p[]; public Point3 p3[]; // eye-coordinate public Point3 P3[]; // world coordinate int x_origin,y_origin; Curve3(){ p = new Point[10]; p3 = new Point3[10]; P3 = new Point3[10]; for (int i = 0; i < 10;i++){ p[i] = new Point(0,0); p3[i] = new Point3(0.,0.,0.); P3[i] = new Point3(0.,0.,0.); } } void SetOrg(int ix_origin, int iy_origin){ x_origin = ix_origin; y_origin = iy_origin; } void copy(int ndeg1){ for(int i = 0; i < ndeg1; i++) { P3[i]= new Point3(0., (double)(p[i].x-x_origin),(double)(p[i].y-y_origin)); p3[i]=P3[i]; } } void polygon3(int ndeg1,Graphics g){ for(int i = 1; i < ndeg1; i++) g.drawLine((int)(p3[i-1].x/p3[i-1].z)+x_origin, (int)(p3[i-1].y/p3[i-1].z)+y_origin,(int)(p3[i].x/p3[i].z)+x_origin, (int)(p3[i].y/p3[i].z)+y_origin); } /* void polygon(int ndeg1,Graphics g){ for(int i = 1; i < ndeg1; i++) g.drawLine(p[i-1].x, p[i-1].y, p[i].x, p[i].y); } void plot(int ndeg1,Graphics g){ for(int i = 0; i < ndeg1; i++) g.fillOval(p[i].x-3, p[i].y-3, 7, 7); } */ void plot3(int ndeg1,Graphics g){ for(int i = 0; i < ndeg1; i++) g.fillOval((int)(p3[i].x/p3[i].z)-2+x_origin, (int)(p3[i].y/p3[i].z)-2+y_origin, 5, 5); } void Polygon3(int ndeg1,Graphics g){ Point[] pnt = new Point[10]; g.setColor(Color.yellow); for(int i = 0; i < ndeg1; i++) { pnt[i] = new Point((int)(p3[i].x/p3[i].z)+x_origin,(int)(p3[i].y/p3[i].z)+y_origin); g.fillOval(pnt[i].x-2,pnt[i].y-2, 5, 5); } g.setColor(Color.darkGray); for(int i = 1; i < ndeg1; i++) g.drawLine(pnt[i-1].x,pnt[i-1].y,pnt[i].x,pnt[i].y); } Point3 eval(int ndeg1,double u){ return castljau(u,ndeg1-1,P3); } void draw3(int ndeg1,Graphics g){ int xold, yold, xnew, ynew, ndiv = 40; xold=(int)(p3[0].x/p3[0].z)+x_origin; yold=(int)(p3[0].y/p3[0].z)+y_origin; for(int i=1; i <= ndiv; i++){ double u = (double)i /(double)ndiv; Point3 current = castljau(u,ndeg1-1,p3); xnew = (int)(current.x/current.z)+x_origin; ynew = (int)(current.y/current.z)+y_origin; g.drawLine(xold,yold,xnew,ynew); xold = xnew; yold=ynew; } } /* ************* 曲線上の座標評価*************************************: */ public Point3 castljau(double u, int ndeg, Point3 p3[]) { double[] wx = new double[10]; double[] wy = new double[10]; double[] ww = new double[10]; for (int i=0; i <=ndeg; i++){ // wx[i] = p3[i].x*p3[i].z; wy[i] = p3[i].y*p3[i].z; wx[i] = p3[i].x; wy[i] = p3[i].y; ww[i] = p3[i].z;} for (int m=1; m <= ndeg; m++) { for (int j=0; j <= ndeg - m; j++) { wx[j] +=(wx[j+1]-wx[j])*u; wy[j] +=(wy[j+1]-wy[j])*u; ww[j] +=(ww[j+1]-ww[j])*u; } } return new Point3(wx[0],wy[0],ww[0]); } } /* ********************************************************************: */ class Vec2{ /* ベクトルクラス */ public double u,v; Vec2(){ } Vec2(double nwx,double nwy){ u=nwx; v=nwy; } void setval(double nwx,double nwy){ /* ベクトルの値を代入 */ u=nwx; v=nwy; } } /* ******************************************************: */ class Point2{ /* ベクトルクラス */ public double x,y; Point2(){ } Point2(double nwx,double nwy){ x=nwx; y=nwy; } void setval(double nwx,double nwy){ /* ベクトルの値を代入 */ x=nwx; y=nwy; } } /* ************* 3D real point class *********************: */ class Point3 { public double x, y, z; Point3() { } Point3(double ox, double oy, double oz) { x = ox; y = oy; z = oz; } } /* *************** class Metaball *************************: */ class Metaball { public double r,v,r2=0.,rs=0.; public Point3 cen; public int s1=0,s2=0; Metaball(double ox,double oy,double oz,double or,double ov) { cen = new Point3(ox,oy,oz); r = or; v = ov; r2= or*or; } void sets(int os1,int os2) { s1 = os1; s2=os2; } }