Le source : CoordonneesHomogenes.java
public class CoordonneesHomogenes {
public float [] c;
public CoordonneesHomogenes() {
c = new float[4];
c[0] = c[1] = c[2] = c[3] = 0;
}
public CoordonneesHomogenes(CoordonneesHomogenes ch) {
c = new float[4];
c[0] = ch.c[0];
c[1] = ch.c[1];
c[2] = ch.c[2];
c[3] = ch.c[3];
}
public CoordonneesHomogenes(Position p) {
c = new float[4];
c[0] = p.c[0];
c[1] = p.c[1];
c[2] = p.c[2];
c[3] = 1.0F;
}
public CoordonneesHomogenes(Direction d) {
c = new float[4];
c[0] = d.c[0];
c[1] = d.c[1];
c[2] = d.c[2];
c[3] = 0.0F;
}
public String toString() {
return(c[0]+" "+c[1]+" "+c[2]+" "+c[3]);
}
public CoordonneesHomogenes composition(TransformationGeometrique tg) {
return(tg.transformation(this));
}
}
public class Position extends CoordonneesHomogenes {
public Position() {
super();
c[3] = 1.0F;
}
public Position(float x,float y,float z) {
super();
c[0] = x;
c[1] = y;
c[2] = z;
c[3] = 1.0F;
}
public Position(CoordonneesHomogenes ch) {
super();
c[0] = ch.c[0];
c[1] = ch.c[1];
c[2] = ch.c[2];
c[3] = 1.0F;
}
}
public class Direction extends CoordonneesHomogenes {
public Direction() {
super();
c[3] = 0.0F;
}
public Direction(float x,float y,float z) {
super();
c[0] = x;
c[1] = y;
c[2] = z;
c[3] = 0.0F;
}
public Direction(CoordonneesHomogenes ch) {
super();
c[0] = ch.c[0];
c[1] = ch.c[1];
c[2] = ch.c[2];
c[3] = 0.0F;
}
}
Le source : TransformationGeometrique.java
public class TransformationGeometrique {
float m[][];
public TransformationGeometrique() {
m = new float[4][4];
for ( int i = 0 ; i < 4 ; i++ )
for ( int j = 0 ; j < 4 ; j++ )
m[i][j] = 0.0F;
for ( int i = 0 ; i < 4 ; i++ )
m[i][i] = 1.0F;
}
public TransformationGeometrique(TransformationGeometrique tg) {
m = new float[4][4];
for ( int i = 0 ; i < 4 ; i++ )
for ( int j = 0 ; j < 4 ; j++ )
m[i][j] = tg.m[i][j];
}
public TransformationGeometrique composition(TransformationGeometrique tg) {
TransformationGeometrique mp = new TransformationGeometrique();
for ( int i = 0 ; i < 4 ; i++ )
for ( int j = 0 ; j < 4 ; j++ ) {
mp.m[i][j] = 0.0F;
for ( int k = 0 ; k < 4 ; k++ )
mp.m[i][j] += m[i][k]*tg.m[k][j]; }
return(mp);
}
public CoordonneesHomogenes transformation(CoordonneesHomogenes p) {
CoordonneesHomogenes ch = new CoordonneesHomogenes();
for ( int i = 0 ; i < 4 ; i++ ) {
ch.c[i] = 0.0F;
for ( int k = 0 ; k < 4 ; k++ )
ch.c[i] += m[i][k]*p.c[k]; }
return(ch);
}
public String toString() {
return(m[0][0]+" "+m[0][1]+" "+m[0][2]+" "+m[0][3]+"\n"+
m[1][0]+" "+m[1][1]+" "+m[1][2]+" "+m[1][3]+"\n"+
m[2][0]+" "+m[2][1]+" "+m[2][2]+" "+m[2][3]+"\n"+
m[3][0]+" "+m[3][1]+" "+m[3][2]+" "+m[3][3]);
}
}
public class Translation extends TransformationGeometrique {
public Translation() {
super();
}
public Translation(float x,float y,float z) {
super();
m[0][3] = x;
m[1][3] = y;
m[2][3] = z;
}
public Translation(CoordonneesHomogenes d) {
super();
m[0][3] = d.c[0];
m[1][3] = d.c[1];
m[2][3] = d.c[2];
}
}
public class Rotation extends TransformationGeometrique {
public Rotation() {
super();
}
public Rotation(float x,float y,float z,float a) throws ArithmeticException {
super();
calcul(x,y,z,a);
}
public Rotation(Direction d,float a) throws ArithmeticException {
super();
calcul(d.c[0],d.c[1],d.c[2],a);
}
public void calcul(float x,float y,float z,float a) throws ArithmeticException {
float d =(float) Math.sqrt(x*x+y*y+z*z);
x /= d;
y /= d;
z /= d;
float c =(float) Math.cos(a);
float s =(float) Math.sin(a);
m[0][0] = x*x+c*(1.0F-x*x);
m[0][1] = x*y*(1.0F-c)-z*s;
m[0][2] = x*z*(1.0F-c)+y*s;
m[1][0] = x*y*(1.0F-c)+z*s;
m[1][1] = y*y+c*(1.0F-y*y);
m[1][2] = y*z*(1.0F-c)-x*s;
m[2][0] = x*z*(1.0F-c)-y*s;
m[2][1] = y*z*(1.0F-c)+x*s;
m[2][2] = z*z+c*(1.0F-z*z);
}
}