float angleX,angleY,angleZ,theta,tempo,rayon,rayoncylindre; Vecteur pointM,pointM0,pointM1,frenetX,frenetX0,frenetY,frenetY0,frenetZ; Vector trajet; float[] matrice; //*************************************************************************** void setup(){ size(700,600); background(255); ellipseMode(CENTER_DIAMETER); pointM=new Vecteur(); pointM0=new Vecteur(); rayon=384.0f; rayoncylindre=1150.0f; angleX=0; angleY=0; angleZ=0; theta=0.0f; pointM0=trajectoire(0,rayoncylindre); pointM1=pointM0.cloner(); frenetX0=new Vecteur(0,1,0); matrice=new float[16]; trajet=new Vector(); } //*************************************************************************** void loop(){ tempo+=0.03f; clear(); push(); placerReperePrincipal(); afficherCycloide(); tracerRoute(); calculerMouvement(); pop(); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void placerReperePrincipal(){ if(mousePressed==true) {angleZ+=(mouseX/50-angleZ)/50;} else {angleX+=(mouseY/50-angleX)/10; angleY+=((mouseX+mouseY)/50-angleY)/10; } push(); rotateZ(-angleZ); rotateY(-angleY); rotateX(-angleX); translate(-200,-500,5000); push(); matrice=g.matrixStack[g.matrixStackDepth-1];//repere R0 pop(); pop(); translate(200,500,-5000); rotateX(angleX); rotateY(angleY); rotateZ(angleZ); //afficherRepere(); noFill(); box(4000); box(4008); push(); rotateY(HALF_PI); fill(255,200,200,40); rect(-2000,-2000,4000,4000);pop(); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void afficherRepere(){ stroke(255,0,0); line(0,0,0,2000,0,0); stroke(0,255,0); line(0,0,0,0,2000,0); stroke(0,0,255); line(0,0,0,0,0,2000); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Vecteur trajectoire(float t,float r){ Vecteur v=new Vecteur(); v.x=r*cos(t); v.y=r*sin(t); v.z=r*cos(2*t); return v; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void tracerRoute(){ Vecteur m=pointM1.cloner(); noFill (); stroke(0, 0, 255); //strokeWeight(2); for(float i=0.05f;i450) tr.removeElementAt(0); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void traceligne(Vecteur v,Vecteur w){ line(v.x,v.y,v.z,w.x,w.y,w.z); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Vecteur coorabs(Vecteur v) { float xa = objectX(v.x, v.y, v.z); float ya = objectY(v.x, v.y, v.z); float za = objectZ(v.x, v.y, v.z); return new Vecteur(xa, ya, za); } //------------------------------------------------------- //------------------------------------------------------- static class Vecteur { float x, y, z; Vecteur() { } Vecteur(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } Vecteur(float x, float y, float z,float lon) { float no=(float) Math.sqrt(x * x + y * y + z * z); no=lon/no; this.x = x*no; this.y = y*no; this.z = z*no; } void place(float xx, float yy, float zz) { this.x = xx; this.y = yy; this.z = zz; } Vecteur normalize() { float length = length(); x /= length; y /= length; z /= length; return this; } Vecteur normalize(float k) { float length = length(); x=x/ length*k; y =y/ length*k; z =z/ length*k; return this; } float length() { return (float) Math.sqrt(x * x + y * y + z * z); } Vecteur cross(Vecteur v2) { Vecteur res = new Vecteur(); res.x = y * v2.z - z * v2.y; res.y =z * v2.x - x * v2.z; res.z = x * v2.y - y * v2.x; return res; } static float dot(Vecteur v1, Vecteur v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } float dot(Vecteur v1) { return v1.x * x + v1.y *y + v1.z *z; } Vecteur mul( float d) { Vecteur res = new Vecteur(); res.x =x * d; res.y = y * d; res.z = z * d; return res; } static Vecteur comb(float a,Vecteur v1,float b, Vecteur v2) { float rx =a* v1.x + b*v2.x; float ry =a* v1.y + b*v2.y; float rz =a* v1.z + b*v2.z; return new Vecteur(rx,ry,rz); } Vecteur ajouter(Vecteur v,float m){ Vecteur res=new Vecteur(x+v.x*m, y+v.y*m,z+v.z*m); return res; } void afficher(String tex,BApplet ba){ ba.println(tex+"x= "+x+" y= "+y+" z= "+z); } Vecteur projete(Vecteur laxe){ laxe.normalize(); Vecteur res=laxe.mul(this.dot(laxe)); return res; } Vecteur projeteSurAxe(Vecteur laxe){ laxe.normalize(); Vecteur res=laxe.mul(this.dot(laxe)); return res; } Vecteur projeteSurPlan(Vecteur laxe){ laxe.normalize(); Vecteur res=laxe.mul(this.dot(laxe)); res=this.ajouter(projeteSurAxe(res),-1); return res; } Vecteur projeteSurPlan(Vecteur laxe,Vecteur unpoint){ laxe.normalize(); Vecteur res=projeteSurPlan(laxe); return res.ajouter(unpoint.projeteSurAxe(res),1); } float donneAngle(Vecteur vc){ return (float) Math.acos(this.dot(vc)/(length()*vc.length())); } Vecteur tourner(Vecteur axe,float angle){//axe est normé et orthogonal à this Vecteur vaxe=axe.mul(this.dot(axe)); Vecteur vx=this.ajouter(vaxe,-1); Vecteur ygrec=axe.cross(this); return vaxe.ajouter(Vecteur.comb((float)Math.cos(angle),this,(float)Math.sin(angle),ygrec),1); } Vecteur cloner() { Vecteur res = new Vecteur(); res.x =x ; res.y = y ; res.z = z ; return res; } }