////////////////////////////////////////////////////////VECTEUR //------------------------------------------------------- //------------------------------------------------------- public 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,PApplet 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; } 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); } public Vecteur cloner() { Vecteur res = new Vecteur(); res.x =x ; res.y = y ; res.z = z ; return res; } }