float angleY,angleX,rx,ry,phi,psi,temps; Vecteur uu,vv,ww,uCw,vCw,aa,bb,uCa,vCb,inter,ptM; BFont metaBold; boolean auto; Vector trajet0,trajet2,trajet3; //------------------------------------------------------- void setup(){ //lights(); auto=true; trajet0=new Vector(); trajet2=new Vector(); trajet3=new Vector(); metaBold = loadFont("Meta-Bold.vlw.gz"); size(620,550); background(187,187,195); angleX=0;rx=0; angleY=0;ry=0; phi=PI/3;//mesure en rd du1/2angle de la premiere rotation psi=PI/2.5;//mesure en rd du 1/2angle de la deuxieme rotation uu=new Vecteur(-3,2,5.5);uu.normalize(); vv=new Vecteur(2,2,2.75);vv.normalize(); ww=uu.cross(vv);//normale au plan (u,v) ww.normalize(); uCw=uu.cross(ww);//troisieme vecteur du repere orthonorme contenant uu et ww uCw.normalize(); vCw=vv.cross(ww);//troisieme vecteur du repere orthonorme contenant vv et ww vCw.normalize(); aa=Vecteur.comb(cos(phi),uCw,sin(phi),ww); bb=Vecteur.comb(cos(psi),vCw,sin(psi),ww); uCa=uu.cross(aa);// normale au plan P1 vCb=vv.cross(bb);//normale au plan P2 inter=uCa.cross(vCb);//directeur de l'intersection ptM=new Vecteur(-1000,4500,500); } //------------------------------------------------------- void keyPressed() { if(key=='a') { auto=!auto;}; if(!auto){ if(key==UP){ ptM.x+=40;}; if(key==DOWN){ ptM.x-=40;}; if(key==RIGHT){ ptM.z+=40;}; if(key==LEFT){ ptM.z-=40;}; } } void loop(){ angleY=(mouseX-width*0.5f)/150.0f; angleX=-(mouseY-height*0.5f)/150.0f; if(auto){ temps+=0.05; if(temps>TWO_PI) temps=0; /* trajet0.removeAllElements(); trajet2.removeAllElements(); trajet3.removeAllElements();*/ ptM.x=-1500+600*cos(3*temps)*cos(temps); ptM.y=4500+600*cos(3*temps)*sin(temps); ptM.z=800+600*cos(3*temps); } clear(); push(); afficherplans(); affichertrajet(); pop(); } //------------------------------------------------------- void affichertrajet(){ stroke(#FF0000); beginShape(LINE_STRIP); for(int i=0; i50) trajet.removeElementAt(0); } //------------------------------------------------------- void afficherplans(){ push(); translate(0,700,-9800); ry+=(angleY-ry)/10; rx+=(angleX-rx)/10; rotateY(ry+PI/5); rotateX(rx+PI/5); stroke(255,0,0); afficherPlan(uu,vv,200,85,100); afficherRepere(uu.mul(5000),uu,ww,uCw); afficherRepere(vv.mul(5000),vv,ww,vCw); Vecteur uuu=coorabs(uu.mul(5000)); Vecteur vvv=coorabs(vv.mul(5000)); afficherPlan(uu,inter,100,100,190); Vecteur interabs=coorabs(inter.mul(5000)); afficherPlan(vv,inter,150,200,60); Vecteur ptM1= afficherSym(ptM,uCa,uu,205,220); Vecteur ptM2=afficherSym(ptM1,vCb,vv,200,200); Vecteur ptM3=afficherSym(ptM1,ww,uu,200,170); Vecteur ptM4= afficherSym(ptM,uCa,inter,235,230); afficherSym(ptM4,vCb,inter,200,250); afficherSym(ptM1,ww,vv,150,160); Vecteur aM=coorabs(ptM); trajetadd( trajet0,aM); Vecteur aM1=coorabs(ptM1); Vecteur aM2=coorabs(ptM2);trajetadd(trajet2,aM2); Vecteur aM3=coorabs(ptM3);trajetadd(trajet3,aM3); Vecteur origine=coorabs( new Vecteur(0,0,-400)); afficherCercle(uu.mul(uu.dot(ptM)),(uu.cross(ptM)).length()); afficherCercle(vv.mul(vv.dot(ptM3)),(vv.cross(ptM3)).length()); afficherCercle(inter.mul(inter.dot(ptM)),(inter.cross(ptM)).length()); pop(); afficherL("V",vvv); afficherL("U",uuu); afficherL("I",interabs); afficherL("M",aM); afficherL("M1",aM1); afficherL("M2",aM2); afficherL("M3",aM3); afficherL("O",origine); } //------------------------------------------------------- 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); } //------------------------------------------------------- void afficherAxe(Vecteur v,float d){ v.normalize(); line(0,0,0,v.x*d,v.y*d,v.z*d);} //------------------------------------------------------- void afficherRepere(Vecteur o,Vecteur a,Vecteur b,Vecteur c){ float d=1000; stroke(255,0,0); line(o.x,o.y,o.z,o.x+d*a.x,o.y+d*a.y,o.z+d*a.z); stroke(0,255,0); line(o.x,o.y,o.z,o.x+d*b.x,o.y+d*b.y,o.z+d*b.z); stroke(0,0,255); line(o.x,o.y,o.z,o.x+d*c.x,o.y+d*c.y,o.z+d*c.z); } //------------------------------------------------------- void afficherPlan(Vecteur a,Vecteur b,float coul1,float coul2,float coul3){ float d=5000; a.normalize(); b.normalize();noStroke(); beginShape(TRIANGLES); fill(coul1,coul2,coul3); vertex(b.x*d,b.y*d,b.z*d); vertex(a.x*d,a.y*d,a.z*d); fill(coul1/2.7,coul2/2.7,coul3/2.7); vertex(0,0,0); endShape(); } Vecteur afficherSym(Vecteur m,Vecteur w1,Vecteur u,int coul1,int coul2){ Vecteur p=w1.mul(w1.dot(m)); Vecteur pu=u.mul(u.dot(m)); Vecteur sym=new Vecteur(m.x-p.x*2 ,m.y-p.y*2 ,m.z-p.z*2); fill(coul1,coul2,coul1/2+coul2/2); noStroke(); beginShape(TRIANGLES); vertex(sym.x ,sym.y,sym.z); vertex(m.x,m.y,m.z); fill(coul1/3,coul2/3,40); vertex(pu.x,pu.y,pu.z); endShape(); return sym; } //------------------------------------------------------- void afficherCercle(Vecteur c,float r){ push(); stroke(250);noFill(); ellipseMode(CENTER_DIAMETER); translate(c.x,c.y,c.z); rotateZ(atan2(c.y,c.x)); rotateY(atan2(sqrt(c.x*c.x+c.y*c.y),c.z)); ellipse(0, 0, 2*r, 2*r); pop(); } //------------------------------------------------------- //------------------------------------------------------- //------------------------------------------------------- //------------------------------------------------------- static class Vecteur { float x, y, z; Vecteur() { } Vecteur(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } void place(float xx, float yy, float zz) { this.x = xx; this.y = yy; this.z = zz; } void normalize() { float length = length(); x /= length; y /= length; z /= length; } 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; } }