• fullscreen
  • Alcys_trianges_homologiques.pde
  • Faisceau.pde
  • Plan.pde
  • import remixlab.proscene.*;
    
    
    Scene scene;
    WorldConstraint contrainteX, libreT, libreTR;
    Plan plan1, plan2, planProjection;
    Faisceau tetraedre;
    
    
    void setup() {
         size(850, 850, P3D);
         scene=new Scene(this);
         scene.setGridIsDrawn(false);
         scene.setAxisIsDrawn(true);
         scene.setRadius(80);
    
         contrainteX=new WorldConstraint();
         contrainteX.setTranslationConstraint(AxisPlaneConstraint.Type.FORBIDDEN, new PVector(0.0f, 0.0f, 0.0f));
         contrainteX.setRotationConstraint(AxisPlaneConstraint.Type.AXIS, new PVector(0.1f, 0.0f, 0.0f));
         libreT=new WorldConstraint();
         libreT.setTranslationConstraint(AxisPlaneConstraint.Type.FREE, new PVector(0.0f, 0.0f, 0.0f));
         libreT.setRotationConstraint(AxisPlaneConstraint.Type.FORBIDDEN, new PVector(0.0f, 0.0f, 0.0f));
         libreTR=new WorldConstraint();
         libreTR.setTranslationConstraint(AxisPlaneConstraint.Type.FREE, new PVector(0.0f, 0.0f, 0.0f));
         libreTR.setRotationConstraint(AxisPlaneConstraint.Type.FREE, new PVector(0.0f, 0.0f, 0.0f));
    
         plan1=new Plan(-200.0, 2.16);
         plan2=new Plan(200.0, 0.9);
         planProjection=new Plan(-400, 0.0);
         planProjection.repere.setPosition(-300, -300, -300);
         planProjection.setCouleur(color(130, 100, 120, 254));
         planProjection.repere.setConstraint(libreTR);
         planProjection.setLargeur(800);
         tetraedre=new Faisceau();
    
    
         scene.camera().setPosition(new PVector(0, 0, 800));
         scene.camera().setOrientation(new Quaternion(0, 0, sin(PI/4), cos(PI/4)));
    }
    
    void draw() {
         background( 170, 170, 250);
         lights();
         directionalLight(55, 55, 255, -0.2, 1, 1);
         planProjection.draw();
         plan1.draw();
         plan2.draw();
         tetraedre.draw();
    }
    
    PVector projection(PVector WP) {
         PVector PO=comb(-1, WP, 1, planProjection.repere.position());
         PVector rep= comb(1, WP, planProjection.normale.dot(PO), planProjection.normale);
         ligne(WP, rep);
         return rep;
    }
    
    
    void    rectangle(color c, float dx, float dy, float ax, float ay) {
         stroke(150);
         fill(c);
         beginShape();
         vertex(dx, dy, 0);
         vertex(ax, dy, 0);
         fill(color(red(c)*2, green(c)*2, blue(c)*2));
         vertex(ax, ay, 0);
         vertex(dx, ay, 0);
         endShape(CLOSE);
    }
    
    //
    void triangle3d(PVector a, PVector b, PVector c) {
    
         beginShape();
         fill(255, 200, 0, 200);
         vertex( a.x, a.y, a.z);
         fill(255, 255, 0, 200);        
         vertex( b.x, b.y, b.z);
         fill(155, 50, 250, 200);
         vertex( c.x, c.y, c.z);
         endShape();
    }     
    void triangle3d(PVector a, PVector b, PVector c, color couleur) {
         stroke(0, 100, 255);
         beginShape();
         fill(couleur);
         vertex( a.x, a.y, a.z);
         vertex( b.x, b.y, b.z);
         vertex( c.x, c.y, c.z);
         endShape();
    }     
    
    PVector comb(float t1, PVector v1, float t2, PVector v2) {
         PVector res=PVector.add(PVector.mult(v1, t1), PVector.mult(v2, t2));
         return res;
    }
    
    float angleEntre(PVector u, PVector v) {
         u.normalize();
         v.normalize();
         float sinus=u.x*v.y-u.y*v.x;
         return asin(sinus);
    }     //
    void balle(int i) {
         pushStyle();  
         pushMatrix();
         fill(0, 0, 255);
         noStroke();
         sphere(6);
         popMatrix();  
         popStyle();
    }
    
    void ligne(PVector a, PVector b) {
    
         line(a.x, a.y, a.z, b.x, b.y, b.z);
    }
    
    
    class Faisceau {
         InteractiveFrame[] points;
         PVector[] dirs, inter1, inter2, delta1, delta2;
         int nbpoints;
    
         Faisceau() {
              nbpoints=4;
              points=new InteractiveFrame[nbpoints];
              dirs=new PVector[nbpoints];
              inter1=new PVector[nbpoints];  
              inter2=new PVector[nbpoints];
              delta1=new PVector[nbpoints];
              delta2=new PVector[nbpoints];        
              for (int i=0;i<nbpoints;i++) {
                   points[i]=new InteractiveFrame(scene);
                   points[i].setConstraint(libreT);
              }
              points[0].setTranslation(39, 209, 123);
              points[1].setTranslation(0, -200, 65);
              points[2].setTranslation(-133, -227, -2);
              points[3].setTranslation(-72, -146, 114);
              directions();
         }
    
    
    
         void draw() {
              PVector v;
              for (int i=0;i<nbpoints;i++) {
                   pushMatrix();
                   points[i].applyTransformation();
                   v=points[i].position();
                   balle(i);
                   popMatrix();
              }
              directions();
              calculer();
              pointsSurOX();
              quadrilatere(points[1].position(), points[2].position(), inter1[2], inter1[1], color(250, 250, 0, 100));
              quadrilatere(points[1].position(), points[3].position(), inter1[3], inter1[1], color(250, 100, 0, 100));
              quadrilatere(points[2].position(), points[3].position(), inter1[3], inter1[2], color(100, 250, 0, 100));
              triangle3d(points[0].position(), inter2[2], inter2[1], color(250, 250, 0, 100));
              triangle3d(points[0].position(), inter2[2], inter2[3], color(250, 100, 0, 100)); 
              triangle3d(points[0].position(), inter2[3], inter2[1], color(100, 250, 0, 100));
    
              dessin2D();
         }
    
         void directions() {
              for (int i=1;i<nbpoints;i++) {
                   dirs[i]=comb(1.0, points[i].position(), -1.0, points[0].position());
              }
         }
    
         void calculer() {
              for (int i=1;i<nbpoints;i++) {
                   inter1[i]=calculInter1(i);
                   inter2[i]=calculInter2(i);
              }
              triangle3d(inter2[1], inter2[2], inter2[3], color(0, 0, 255));
              triangle3d(inter1[1], inter1[2], inter1[3], color(0, 0, 255));
         } 
    
         PVector calculInter1(int n) {
              PVector z1=comb(1, plan1.repere.inverseCoordinatesOf(new PVector(0, 0, 1)), -1, plan1.repere.position());
              float lambda=z1.dot(comb(-1, points[0].position(), 1, plan1.repere.position()))/z1.dot(dirs[n]);
              return comb(1, points[0].position(), lambda, dirs[n]);
         }
         PVector calculInter2(int n) {
              PVector z1=comb(1, plan2.repere.inverseCoordinatesOf(new PVector(0, 0, 1)), -1, plan2.repere.position());
              float lambda=z1.dot(comb(-1, points[0].position(), 1, plan2.repere.position()))/z1.dot(dirs[n]);
              return comb(1, points[0].position(), lambda, dirs[n]);
         }
    
         PVector couperLaxe(PVector a, PVector b) {
              PVector dirAB=comb(1, b, -1, a);
    
    
              float lambda=(dirAB.y!=0)? -a.y/dirAB.y: -a.z/dirAB.z;
              return comb(1, a, lambda, dirAB);
         }
    
         void pointsSurOX() {
              stroke(0);
              delta1[1]=couperLaxe(inter1[1], inter1[2]);
              delta1[2]=couperLaxe(inter1[2], inter1[3]);
              delta1[3]=couperLaxe(inter1[1], inter1[3]);
              delta2[1]=couperLaxe(inter2[1], inter2[2]);
              delta2[2]=couperLaxe(inter2[2], inter2[3]);
              delta2[3]=couperLaxe(inter2[1], inter2[3]);
    
              pushStyle();
              stroke(0, 255, 0);
              strokeWeight(2);
              ligne(inter1[1], delta1[1]);
              ligne(inter1[2], delta1[2]);
              ligne(inter1[3], delta1[3]);
    
    
              ligne(inter2[1], delta2[1]);
              ligne(inter2[2], delta2[2]);
              ligne(inter2[3], delta2[3]);
              popStyle();
              color c=color(0, 0, 255, 10);
              triangle3d(inter1[1], delta1[1], delta1[3], c);
              triangle3d(inter1[2], delta1[2], delta1[1], c);
              triangle3d(inter1[3], delta1[3], delta1[2], c);
              c=color(255, 0, 0, 10);  
              triangle3d(inter2[1], delta2[1], delta2[3], c);
              triangle3d(inter2[2], delta2[2], delta2[1], c);
              triangle3d(inter2[3], delta2[3], delta2[2], c);
    
              quadrilatere(inter1[1], inter2[1], inter2[2], inter1[2], color(155, 180, 255));
              quadrilatere(inter1[1], inter2[1], inter2[3], inter1[3], color(55, 50, 200));
              quadrilatere(inter1[2], inter2[2], inter2[3], inter1[3], color(155, 100, 200));
         }
    
    
    
    
    
    
         void quadrilatere(PVector u1, PVector u2, PVector v1, PVector v2, color c) {
              fill(c);
              // stroke(0);
              noStroke();
              beginShape();
              vertex(u1.x, u1.y, u1.z);
              vertex(u2.x, u2.y, u2.z);
              vertex(v1.x, v1.y, v1.z);
              vertex(v2.x, v2.y, v2.z);
              endShape(CLOSE);
         }
    
         void dessin2D() {
              stroke(0, 0, 100);
    
              PVector pt0=projection(points[0].position());
              PVector pt1=projection(points[1].position());       
              PVector pt2=projection(points[2].position()); 
              PVector pt3=projection(points[3].position()); 
    
              PVector u12=projection(delta1[1]);
              PVector u23=projection(delta1[2]);
              PVector u13=projection(delta1[3]);
    
              PVector d12=projection(delta2[1]);
              PVector d23=projection(delta2[2]);
              PVector d13=projection(delta2[3]); 
              PVector pi12=projection(inter1[1]);
              PVector pi23=projection(inter1[2]);       
              PVector pi13=projection(inter1[3]);  
              PVector pj12=projection(inter2[1]); 
              PVector pj23=projection(inter2[2]); 
              PVector pj13=projection(inter2[3]); 
    
    
              strokeWeight(2);
              stroke(255);
              ligne(pt0, pt1); 
              ligne(pt0, pt2);    
              ligne(pt0, pt3); 
    
              ligne(pi12, u12);
              ligne(pi23, u23);
              ligne(pi13, u13);
    
              ligne(pj12, d12);
              ligne(pj23, d23);
              ligne(pj13, d13);
              stroke(255, 0, 0);  
              strokeWeight(4);
              ligne(u12, u13);
              ligne(u12, u23); 
              ligne(u23, u13);
              strokeWeight(1);  
              triangle3d(pi12, pi13, pi23, color(0,0, 255, 254));
              triangle3d(pj12, pj13, pj23, color(0,0, 255, 254));
         }
    }
    
    
    class Plan {
         InteractiveFrame repere;    
         float posix, angle, largeur, longueur;
         PVector normale;
         color col;
    
    
    
         Plan(float posx, float an) {
              posix=posx;
              angle=an;
              longueur=-2.0f*posix;
              largeur=200;
              normale=new PVector(0, 0, 1);
              col=color(55, 55, 100, 254);
              repere=new InteractiveFrame(scene);
              repere.setTranslation(posx, 0, 0);
              repere.setRotation(new Quaternion(new PVector(1, 0, 0), angle));
              repere.setConstraint(contrainteX);
         }
    
         void draw() {
              pushMatrix();
              repere.applyTransformation();
              normale=  repere.inverseTransformOf(new PVector(0, 0, 1));
              noStroke();
              fill(255, 0, 0);
              sphere(5);
              rectangle(col, 0, 0, longueur, largeur );
              popMatrix();
         }
         void setLargeur(float lar) {
              largeur=lar;
         }
         void setCouleur(color c) { 
              col=c;
         }
         void getNormaleDansWorld() {
              normale=  repere.inverseTransformOf(new PVector(0, 0, 1));
              println("normale au plan =  "+ normale.x+"   "+ normale.y+"   "+ normale.z);
         }
    }
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    jacques maire

    homological triangles

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    Triangles homologiques obtenus par projection d'un tétraèdre tronqués.
    Les sphères bleues et rouges sont interactives. Par click and drag right or left, elles transforme la figure. Pas trop, merci pour elle.
    rotation : click left and drag
    translation : click right and drag

    You need to login/register to comment.