 
                                Grafikprogrammierung
mittels Java3D
Transformationen
Frank Krack
Geometrische Transformationen
Skalierung
Translation
Rotation
Objekte in Java3D
Objekte werden anhand der Fläche gespeichert
Einfache Vorstellung mit Punkten
alle Punkte eines Objekts
V = {vi | vi = (xi, yi, zi) Є R3, i Є N}
Translation
Verschiebung
Addition aller Punkte  t x 
mit Translationsvektor  t y 
t 
 z
 x   tx   x  tx 
    
 y   ty    y  ty 
z    
   tz   z  tz 
tx = 1.0, ty = 1.0, tz = -1.5
Homogene Translation
Translation als Matrizenmultiplikation
homogenen Koordinaten
1
0
0
0
0 0 tx   x   x  tx 
   
1 0 ty   y   y  ty 
   
0 1 tz
z
z  tz 
   
0 0 1  1  1
Skalierung
Dehnung / Stauchung
 x 
 
 Multiplikation aller Punkte   y 
 
mit Skalierungsvektor
 z
 x   x   x * x 
    
 y    y    y * y 
 z      z * 
z 
   z 
 x = 0.25,  y = 0.5,  z = 1.0
Homogene Skalierung
Skalierung als Matrizenmultiplikation
homogenen Koordinaten
 x
0
0
0
0
0
y
0
0
z
0
0
0   x   x * x 
   
0   y   y * y 
   
0
z
z
*
z 
   
1  1  1
Rotation
Drehung um eine Achse
Multiplikation aller Punkte
mit Rotationsmatrix
0
1
RX ( )  p   0 cos 
 0 sin 
x
  x 
   
 sin     y    y * cos   z * sin  
cos    z   y * sin   z * cos  
0
Rotation
Rotation um Y-Achse
 cos 
RY ( )  p   0
  sin 
0 sin    x   x * cos   z * sin  
   
1
0  y  
y
0 cos    z    x * sin   z * cos  
Rotation um Z-Achse
 cos 
RZ ( )  p   sin 
 0
 sin 
cos 
0
0   x   x * cos   y * sin  
   
0    y    x * sin   y * cos  
1   z  
z
Homogene Rotation
Rotation als Matrixmultiplikation mit homogenen
Koordinaten
z.B. Drehung um Z-Achse
 cos 
 sin 
 0
 0
 sin 
cos 
0
0
0 0   x   x * cos   y * sin  
   
0 0   y   x * sin   y * cos  
   
1 0
z
z
   
0 1  1  1
Mathematik in Java
Matrix- und Vektoroperationen sind im
javax.vecmath-Package enthalten
Klassen:
Vector3f, Vector3d
Matrix3f, Matrix3d, Matrix4f, Matrix4d
Unterstützung für
Vektoroperationen (z.B. Skalar- und Vektorprodukt)
Matrixoperationen (Transformation von Punkten)
Transform3D
speichert eine Transformation in einer
4x4-Matrix
Konstruktor
Transform3D t3d_trans = new Transform3D();
Standardkonstruktur initialisiert die Matrix als Einheitsmatrix
Transform3D t3d_trans = new Transform3D(float[] matrix);
Erzeugt eine Transformationsobjekt und übergibt in einem
16 Elemente großen Array die Transformationsmatrix.
Package: javax.media.j3d.Transform3D
Transform3D
Funktionen
void setTranslation(Vector3d trans)
setzt nur die Translationswerte des Vektors trans in die
Transformationsmatrix
void set(Vector3f trans)
Änderung der Matrix in Einheitsmatrix mit Translationswerten trans
void setScale(Vector3d scale)
void setScale(double scale)
Setzt den Wert der Transformation auf eine Skalierung für alle drei
Dimensionen unterschiedlich bzw. gleichmäßig
Transform3D
Funktionen
void rotX(double angle)
void rotY(double angle)
void rotZ(double angle)
Setzt den Wert der Transformation auf
eine Rotation um die entsprechende
Achse. Der Winkel angle ist im Bogenmass.
3
1 
4
315
2
360
4
45
3
2
270
1
Umrechnug:
Math.PI / 2.0d = Math.toRadians (90.0d);
2
90
4
225
180
3
4
135
zusammengesetzte Transformationen
Folge von Transformationen
Matrizen-Produkt
Vorsicht!!!
Die Matrixmultiplikation ist
assoziativ: A*B*C = (A*B)*C = A*(B*C)
nicht kommutativ: A*B != B*A
Translation * Rotation != Rotation * Translation
Rotation1 * Rotation2 != Rotation2 * Rotation1
wichtige Reihenfolge
Zusammengestzte Transformationen
xr
yr
zr 
xr
Rotation um Achse im Punkt x
r
Translation zum Ursprung T1  xr
 Rotation Rz( )
Translation zum Startpunkt T2 xr
Rxr
yr
zr
/ 
= T2 * Rz( ) * T1
yr
 yr
yr
zr 
 zr 
zr 
yr
zr 
Transform3D
Funktionen
void set (Vector3f trans, float scale)
void set (Vector3d trans, double scale)
binden gleichzeitig eine Translation und eine Skalierung in die Matrix
ein
void setRotation(AxisAngle4d)
Rotation um eine beliebige Achse im Raum
void mul(Transform3D t3d_t1)
this = this * t3d_t1
void mul(Transform3D t3d_t1, Transform3D t3d_t2)
führen Multiplikation der Matrizen aus
this = t3d_t1 * t3d_t2
TransformGroup
Verzweigung im Szenen-Graphen, die eine
Transformation speichert
Konstruktor
TransformGroup tg = new TransformGroup()
Standardkontruktor, der eine Verzweigung mit einer neutralen
Transformation (Einheitsmatrix) erzeugt
TransformGroup tg = new TransformGroup(Transform3D transform)
Erzeugt eine Verzweigung mit einem Transform3D-Objekt
Package: javax.media.j3d.TransformGroup
TransformGroup
Funktionen
void setTransform(Transform3D transform)
Setzt die Transformation der TransformGroup
void addChild(Node child)
- Hängt einen Knoten als Kind ein
- Kind kann wieder eine TransformGroup sein
- nachfolgende Transformation ist relativ zur vorhergehenden
Quellen
Sun Java 3D Tutorial
http://developer.java.sun.com/developer/onlineTraining/java3d/
Skript Graphische Datenverarbeitung
Prof. Dr. Werner Heinzel