Reprise des classes du TP n°7

Vecteur.java Vecteur4.java
Matrice.java Matrice44.java

L'implantation est réalisée en coordonnées homogènes.

Horizontale.gif (2348 octets)

Une première classe CoodonneesHomogenes est dérivée de la classe Vecteur4 pour représenter des coordonnées homogènes 3D.

/* Auteur: Nicolas JANEY                                */
/* nicolas.janey@univ-fcomte.fr                         */
/* Novembre 2006                                        */

public class CoordonneesHomogenes extends Vecteur4 {

  public CoordonneesHomogenes() {
    super();
  }

  public CoordonneesHomogenes(float x,float y,float z,float t) {
    super(x,y,z,t);
  }

  public CoordonneesHomogenes(CoordonneesHomogenes ch) {
    super(ch.c[0],ch.c[1],ch.c[2],ch.c[3]);
  }
  
  public void setX(float x) {
    c[0] = x;
  }
  
  public float getX() {
    return(c[0]);
  }
  
  public void setY(float y) {
    c[1] = y;
  }
  
  public float getY() {
    return(c[1]);
  }
  
  public void setZ(float z) {
    c[2] = z;
  }
  
  public float getZ() {
    return(c[2]);
  }
  
  public void setT(float t) {
    c[3] = t;
  }
  
  public float getT() {
    return(c[3]);
  }
}

CoordonneesHomogenes.java

Horizontale.gif (2348 octets)

La classe Position est dérivée de la classe CoordonneesHomogenes pour représenter des positions dans un espace 3D (4ème coordonnée initialisée à 1.0F).

/* Auteur: Nicolas JANEY                                */
/* nicolas.janey@univ-fcomte.fr                         */
/* Novembre 2006                                        */

public class Position extends CoordonneesHomogenes {

  public Position() {
    super(0.0F,0.0F,0.0F,1.0F);
  }

  public Position(float x,float y,float z) {
    super(x,y,z,1.0F);
  }

  public Position(Position p) {
    super(p);
  }
}

Position.java

Horizontale.gif (2348 octets)

La classe Direction est dérivée de la classe CoordonneesHomogenes pour représenter des directions dans un espace 3D (4ème coordonnée initialisée à 0.0F).

/* Auteur: Nicolas JANEY                                */
/* nicolas.janey@univ-fcomte.fr                         */
/* Novembre 2006                                        */

public class Direction extends CoordonneesHomogenes {

  public Direction() {
    super(0.0F,0.0F,0.0F,0.0F);
  }

  public Direction(float x,float y,float z) {
    super(x,y,z,0.0F);
  }

  public Direction(Direction p) {
    super(p);
  }

  public Direction(Position pi,
                   Position pf) throws ArithmeticException {
    float dx = pf.c[0]-pi.c[0];
    float dy = pf.c[1]-pi.c[1];
    float dz = pf.c[2]-pi.c[2];
    float d =(float) Math.sqrt(dx*dx+dy*dy+dz*dz);
    if ( d == 0.0F ) {
      throw new ArithmeticException(); }
    c = new float[4];
    c[0] = dx/d;
    c[1] = dy/d;
    c[2] = dz/d;
    c[3] = 0.0F;
  }
}

Direction.java

Horizontale.gif (2348 octets)

La classe Transformation est dérivée de la classe Matrice44 pour représenter des transformations géométriques quelconques en coordonnées homogènes dans un espace 3D.
Le constructeur sans paramètre dérive directement de celui de la classe Matrice44 qui crée une matrice identité.
Trois méthodes sont développées pour:

/* Auteur: Nicolas JANEY                                */
/* nicolas.janey@univ-fcomte.fr                         */
/* Novembre 2006                                        */

public class Transformation extends Matrice44 {

  public Transformation() {
    super();
  }
  
  public Transformation(float [][] t) {
    super(t);
  }
  
  public Position multiplication(Position p) {
    Vecteur v = multiplication((Vecteur) p);
    return(new Position(v.c[0],v.c[1],v.c[2]));
  }
  
  public Direction multiplication(Direction d) {
    Vecteur v = multiplication((Vecteur) d);
    return(new Direction(v.c[0],v.c[1],v.c[2]));
  }  
  
  public Transformation multiplication(Transformation t) {
    Matrice m = multiplication((Matrice) t);
    return(new Transformation(m.c));
  }  
}

Transformation.java

Horizontale.gif (2348 octets)

La classe Translation est dérivée de la classe Transformation.

/* Auteur: Nicolas JANEY                                */
/* nicolas.janey@univ-fcomte.fr                         */
/* Novembre 2006                                        */

public class Translation extends Transformation {

  public Translation(float x,float y,float z) {
    super();
    c[0][3] = x;
    c[1][3] = y;
    c[2][3] = z;
  }

  public Translation(Direction d) {
    super();
    c[0][3] = d.getX();
    c[1][3] = d.getY();
    c[2][3] = d.getZ();
  }
}

Translation.java

Horizontale.gif (2348 octets)

La classe RotationX est dérivée de la classe Transformation.

/* Auteur: Nicolas JANEY                                */
/* nicolas.janey@univ-fcomte.fr                         */
/* Novembre 2006                                        */

public class RotationX extends Transformation {

  public RotationX(float a) {
    super();
    a = a/180.0F*(float) Math.PI;
    float cs =(float) Math.cos(a);
    float sn =(float) Math.sin(a);
    c[1][1] = c[2][2] = cs;
    c[1][2] = -sn;
    c[2][1] = sn;
  }
}

RotationX.java

Horizontale.gif (2348 octets)

La classe RotationY est dérivée de la classe Transformation.

/* Auteur: Nicolas JANEY                                */
/* nicolas.janey@univ-fcomte.fr                         */
/* Novembre 2006                                        */

public class RotationY extends Transformation {

  public RotationY(float a) {
    super();
    a = a/180.0F*(float) Math.PI;
    float cs =(float) Math.cos(a);
    float sn =(float) Math.sin(a);
    c[0][0] = c[2][2] = cs;
    c[0][2] = sn;
    c[2][0] = -sn;
  }
}

RotationY.java

Horizontale.gif (2348 octets)

La classe RotationZ est dérivée de la classe Transformation.

/* Auteur: Nicolas JANEY                                */
/* nicolas.janey@univ-fcomte.fr                         */
/* Novembre 2006                                        */

public class RotationZ extends Transformation {

  public RotationZ(float a) {
    super();
    a = a/180.0F*(float) Math.PI;
    float cs =(float) Math.cos(a);
    float sn =(float) Math.sin(a);
    c[0][0] = c[1][1] = cs;
    c[0][1] = -sn;
    c[1][0] = sn;
  }
}

RotationZ.java

Horizontale.gif (2348 octets)

La classe Rotation est dérivée de la classe Transformation. Elle comporte les constructeurs pour:

/* Auteur: Nicolas JANEY                                */
/* nicolas.janey@univ-fcomte.fr                         */
/* Novembre 2006                                        */
/* Transformation geometrique en coordonnees homogenes  */
/* pour la realisation de rotations autour d'un axe     */
/* arbitraire passant ou non par l'origine              */

public class Rotation extends Transformation {

  public Rotation(float a,
                  float dx,float dy,float dz) throws ArithmeticException {
    super();
    remplissage(a,dx,dy,dz);
  }

  public Rotation(float a,
                  Direction d) throws ArithmeticException {
    super();
    remplissage(a,d.getX(),d.getY(),d.getZ());
  }

  public Rotation(float a,
                  float x,float y,float z,
                  float dx,float dy,float dz) throws ArithmeticException {
    super();
    remplissage(a,x,y,z,dx,dy,dz);
  }

  public Rotation(float a,
                  Position p,Direction d) throws ArithmeticException {
    super();
    remplissage(a,p.getX(),p.getY(),p.getZ(),d.getX(),d.getY(),d.getZ());
  }

  private void remplissage(float a,
                           float x,float y,float z) throws ArithmeticException {
    a = a/180.0F*(float) Math.PI;
    float c =(float) Math.cos(a);
    float s =(float) Math.sin(a);
    float d =(float) Math.sqrt(x*x+y*y+z*z);
    if ( d == 0 ) {
      throw new ArithmeticException(); }
    x /= d;
    y /= d;
    z /= d;
    float x2 = x*x;
    float y2 = y*y;
    float z2 = z*z;
    float xs = x*s;
    float ys = y*s;
    float zs = z*s;
    float mc = 1.0F - c;
    float xymc = x*y*mc;
    float xzmc = x*z*mc;
    float yzmc = y*z*mc;
    this.c[0][0] = x2+c*(1.0F-x2);
    this.c[0][1] = xymc-zs;
    this.c[0][2] = xzmc+ys;
    this.c[1][0] = xymc+zs;
    this.c[1][1] = y2+c*(1.0F-y2);
    this.c[1][2] = yzmc-xs;
    this.c[2][0] = xzmc-ys;
    this.c[2][1] = yzmc+xs;
    this.c[2][2] = z2+c*(1.0F-z2);
  }

  private void remplissage(float a,
                           float px,float py,float pz,
                           float ax,float ay,float az) throws ArithmeticException {
    Translation ti = new Translation(-px,-py,-pz);
    Rotation r = new Rotation(a,ax,ay,az);
    Translation tf = new Translation(px,py,pz);
    Transformation t = tf.multiplication(r).multiplication(ti);
    for ( int i = 0 ; i < 4 ; i++ )
      for ( int j = 0 ; j < 4 ; j++ )
        c[i][j] = t.c[i][j];
  }
}

Rotation.java

Horizontale.gif (2348 octets)

La classe LookAt est dérivée de la classe Transformation.

/* Auteur: Nicolas JANEY                                */
/* nicolas.janey@univ-fcomte.fr                         */
/* Novembre 2006                                        */
/* Transformation geometrique en coordonnees homogenes  */
/* pour un changement de repere de type repere global   */
/* vers repere observateur avec l'axe (0.0,1.0,0.0)     */
/* vertical en coordonnees observateur                  */

public class LookAt extends Transformation {

  public LookAt(float pox,float poy,float poz,
                float pvx,float pvy,float pvz) throws ArithmeticException {
    super();
    remplissage(pox,poy,poz,pvx,pvy,pvz);
  }

  public LookAt(Position po,Position pv) throws ArithmeticException {
    super();
    remplissage(po.getX(),po.getY(),po.getZ(),
                pv.getX(),pv.getY(),pv.getZ());
  }

  private void remplissage(float pox,float poy,float poz,
                           float pvx,float pvy,float pvz) throws ArithmeticException {
    float nx = pvx-pox;
    float ny = pvy-poy;
    float nz = pvz-poz;
    float d =(float) Math.sqrt(nx*nx+ny*ny+nz*nz);
    if ( d == 0 ) {
      throw new ArithmeticException(); }
    nx /= d;
    ny /= d;
    nz /= d;
    float a = 1.0F/(float) Math.sqrt(1.0F-ny*ny);
    this.c[0][0] = -a*nz;
    this.c[0][2] = a*nx;
    this.c[0][3] = a*(pox*nz-poz*nx);
    this.c[1][0] = -a*nx*ny;
    this.c[1][1] = 1.0F/a;
    this.c[1][2] = -a*ny*nz;
    this.c[1][3] = a*ny*(pox*nx+poz*nz)-poy/a;
    this.c[2][0] = -nx;
    this.c[2][1] = -ny;
    this.c[2][2] = -nz;
    this.c[2][3] = pox*nx+poy*ny+poz*nz;
  }
}

LookAt.java

Horizontale.gif (2348 octets)

Aide de cette hiérarchie de classes au format Javadoc

Horizontale.gif (2348 octets)

RETOUR