Transformationen

Werbung
Transformationen
09-Transformationen
Transformationen werden affine Transformationen im Rn betrachtet.
Alle derartigen Transformationen lassen sich darstellen als:
y = A x + b wobei A die quadratische Transformationsmatrix und b der
Verschiebungsvektor ist.
Wenn b=0 ist, so handelt es sich um eine lineare Transformation.
Die Anwendung zweier affiner Transformationen ergibt:
y= A2 (A1 x + b1) + b2 = A2A1 x + A2b1 + b2 = A x + b mit
A = A2A1 und b = A2b1 + b2
Für lineare Transformationen entfallen die Verschiebungsanteile.
Die linearen Anteile ergeben sich immer durch Multiplikation der
Transformationmatrizen.

Die mehrfache Anwendung von linearen Transformationen wird durch
Matrixmultiplikationen relisiert.
Die mehrfache Anwendung von Verschiebungen führt auf kompliziertere
Matrix-Vektor-Operationen.
Als
09-Transformationen
2
Homogene Koordinaten
Beispiel
w
R1
1
0
0
0.5
1
R1
0.5
1
R1
09-Transformationen
x
3
Punkt x im Rn wir identifiziert mit der Geraden, die durch die Punkte
(tx,t) im Rn+1 gebildet wird.
 Jeder Punkt (x,w) mit x∈Rn und w≠0 repräsentiert genau einen Punkt
aus Rn nämlich x/w.
Affine Transformationen stellen sich in affinen Koordinaten
folgendermaßen dar:
Jeder
 y   Ax  b   A b  x 
   
  
 
 1   1   0 1  1 

Alle affinen Transformationen im Rn lassen sich durch Übergang zu
den homogenen Koordinaten als lineare Transformationen darstellen.
 Mehrfachanwendungen von affinen Transformationen lassen sich als
Matrixmultiplikationen darstellen.
Kosten: Es muss mit größeren Matrizen gerechnet werden.
Die letzte Zeile der Matrix ist trivial und wird deshalb nicht gespeichert.
09-Transformationen
4
Elementare Transformationen
Alle
affinen Transformationen lassen sich durch einige wenige elementare
Transformationen durch Kombination erzeugen.
Jede affine Transformation ist die Kombination aus einer linearen
Transformation und einer Verschiebung:
 y   A b  x   I b  A 0  x 
   
   

 
 1   0 1  1   0 1  0 1  1 
 I b

A  
 0 1
T
09-Transformationen
5
Drehung
R2 gibt es genau eine Drehung um den Koordinatenursprung mit dem
Winkel α:
Im
 cos   sin   0 


R
A   sin   cos  0 
 0
0
1 

R3 gibt es drei Drehungen um die Achsen mit dem Winkel α:
 cos  0  sin   0 
0
0
0
1




1
0
0
 0
R
 0 cos   sin   0 
R
A

Ax  
y
  sin   0 cos  0 
0 sin   cos  0 
Im

0


0


 0

0
1

 cos   sin   0

 sin   cos  0
R
Az  
0
0
1

 0
0
0

0
0

1 
0

0
0

1 
Drehungen erhalten sowohl die Winkel, die Längen als auch die
Abstände zum Koordinatenursprung.
09-Transformationen
6
Skalierungen
Skalierungen
sind Multiplikationen der einzelnen Koordinaten mit konstanten
Faktoren.
Es gibt im Rn genau n Skalierungen.
 sx

S
Ax   0
0

 sx

0
S
Ax  
0

0
0 0

1 0
0 1 
1 0

S
Ay   0 s y
0 0

0 0 0
1 0



1 0 0
 0 sy
S
Ay  

0 1 0
0 0


0 0 1
0 0
0 0

0 0
1 0

0 1
0

0
1 
1

0
S
Az  
0

0
09-Transformationen
0
0
1 0
0 sz
0 0
0

0
0

1
7
Scherungen
Im
zweidimensionalen Fall ergeben Rotation und Skalierungen genau drei
Transformationen. Die lineare Transformationsmatrix enthält aber vier
Parameter. Man benötigt also noch eine elementare Transformation, um
alle Transformationen beschreiben zu können. Dieses kann z.B. eine
Scherung sein.
Im dreidimensionalen Fall ergeben drei Rotationen und drei Skalierungen
sechs Transformationen. Es fehlen also noch drei Scherungen um alle
Parameter festzulegen.
Scherungen verändern die Längen und Winkel. Parallelität bleibt jedoch
erhalten.
 1 s xy

X
Axy   0 1
0 0

0

0
1 
1

X
Ayx   s yx
 0

09-Transformationen
0 0

1 0
0 1 
8
Die
Hintereinanderausführung von Transformationen ist nicht kommutativ!
Die Reihenfolge der Transformationen ist wichtig!
Beispiel Rotation um einen gegebenen Punkt (x0,y0) um einen Winkel α.
1 0
 y 
    0 1
 1 0 0

x0  cos   sin   0  1 0  x0 


 x 
y0  sin   cos  0  0 1  y0  
1






1  0
0
1  0 0 1 
 cos   sin   x0  x0 cos   y0 sin  
 x 
 y 
    sin   cos  y0  x0 sin    y0 cos  
1
1  0


0
1


09-Transformationen
9
Die Klasse AffineTransform
Die
Klasse AffineTransform dient der Beschreibung affiner
Transformationen in java.
Die Klasse ist in AWT enthalten und wird hauptsächlich in Graphics2D
verwendet.
java.awt.geom.AffineTransform
Die Klasse ermöglicht:
•Die Erzeugung von affinen Transformationen
•Die Verkettung von affinen Transformationen
•Die Invertierung von affinen Transformationen
•Die Anwendung von affinen Transformationen auf Shape-Objekte
09-Transformationen
10
Konstruktoren
AffineTransform()
erzeugt die Identische Abbildung
AffineTransform(AffineTransform Tx)
erzeugt eine Kopie der affinen Transformation Tx
AffineTransform(double[] flatmatrix)
erzeugt aus dem Vektor flatmatrix eine affine
Transformation mit der zugehörigen Matrix.
•flatmatrix.length<6  lineare Transformation mit der
Matrix
•flatmatrix.length>=6  affine Transformation mit der
Matrix
AffineTransform(double m00, double m10,
double m01, double m11, double m02,
double m12)
erzeugt eine affine Transformation mit der Matrix
Die letzten beiden gibt es auch mit float-Variablen
09-Transformationen
 1 0 0


 0 1 0
 0 0 1


 flatmatrix0

 flatmatrix1

0

 flatmatrix0

 flatmatrix1

0

flatmatrix2 0 

flatmatrix3 0 
0
1 
flatmatrix2
flatmatrix3
0
flatmatrix4

flatmatrix5

1

 m00 m01 m02 


 m10 m11 m12 
 0
0
1 

11
Fabrikmethoden
public
static AffineTransform
getRotateInstance (double theta)
erzeugt eine Rotations-Transformation
 costheta
public static AffineTransform

getRotateInstance (double theta,  sin theta

0

double x, double y)
erzeugt eine Rotations-Transformation um den
Punkt (x,y)
public static AffineTransform
getTranslateInstance (double tx,
double ty)
erzeugt eine Translations-Transformation mit der
Verschiebung (tx,ty)
public static AffineTransform
getScaleInstance (double sx,
double sy)
erzeugt eine Skalierungs-Transformation mit den
Faktoren (sx,sy)
09-Transformationen
 costheta  sin theta 0 


 sin theta costheta 0 

0
0
1 

 sin theta x  x costheta  y sin theta

costheta y  x sin theta  y costheta

0
1

 1 0 tx 


0
1
ty


0 0 1 


 sx

0
0

0

sy 0 
0 1 
0
12
public
static AffineTransform
getShearInstance (double shx, double shy)
erzeugt eine Scherungs-Transformation mit den Faktoren
(shx,shy)
09-Transformationen
 1 shx 0 


 shy 1 0 
 0
0 1 

13
Abfragemethoden
public
int getType()
bestimmt den Typ der Transformation:
TYPE_IDENTITY : Identische Transformation
TYPE_GENERAL_TRANSFORM : allgemeine Transformation
TYPE_TRANSLATION : enthält Translationsanteil (m02≠0 oder m12≠0)
TYPE_UNIFORM_SCALE : gleichmäßig Skalierung (m00==m11≠1)
TYPE_GENERAL_SCALE : ungleichmäßige Skalierung (m00≠1, m11≠1,
m00≠m11)
TYPE_QUADRANT_ROTATION : Rotation um Vielfache von 90°
TYPE_GENERAL_ROTATION : allgemeine Rotation
mehrfache Typen werden durch oder - Operation gebildet
public double getDeterminant()
berechnet die Determinante der Transformationsmatrix
= m00*m11-m01*m10
09-Transformationen
14
public
void getMatrix(double[] flatmatrix)
bestimmt die Transformationsmatrix:
flatmatrix.length<6 flatmatrix={m00, m10, m01, m11}
flatmatrix.length>=6 flatmatrix={m00, m10, m01, m11,
m02, m12}
public double getScaleX()
liefert m00
public double getScaleY()
liefert m11
public double getShareX()
liefert m01
public double getShareY()
liefert m10
public double getTranslateX()
liefert m02
public double getTranslateY()
liefert m12
09-Transformationen
15
Verkettung von Transformationen
public
void concatenate(AffineTransform Tx)
verkettet die aktuelle Transformation mit Tx
[this] = [this] * [Tx]
public void preConcatenate(AffineTransform Tx)
verkettet die aktuelle Transformation mit Tx
[this] = [Tx] * [this]
public void translate(double tx, double ty)
entspricht
concatenate(AffineTransform.getTranslateInstance(tx,ty))
public void rotate(double theta)
entspricht
concatenate(AffineTransform.getRotateInstance(theta))
 public void rotate(double theta, double x, double y)
entspricht concatenate(AffineTransform.getRotateInstance
(theta, x, y))
09-Transformationen
16
public
void scale(double sx, double sy)
entspricht concatenate(AffineTransform.getScaleInstance
(sx, sy))
public void share(double shx, double shy)
entspricht concatenate(AffineTransform.getShareInstance
(shx, shy))
09-Transformationen
17
Überschreiben der Transformation
public
void setToIdentity()
ersetzt die Transformation durch die Identität
public void setToTranslation(double tx, double ty)
ersetzt die Transformation durch die Translation
AffineTransform.getTranslateInstance(tx,ty)
public void setToRotation(double theta)
ersetzt die Transformation durch die Rotation
AffineTransform.getRotateInstance(theta)
public void setToRotation(double theta, double x,
double y)
ersetzt die Transformation durch die Rotation
AffineTransform.getRotateInstance(theta, x, y)
public void setToScale(double sx, double sy)
ersetzt die Transformation durch die Rotation
AffineTransform.getScaleInstance(sx, sy)
public void setToShear(double shx, double shy)
ersetzt die Transformation durch die Rotation
AffineTransform.getScaleInstance(sx, sy)
09-Transformationen
18
public
AffineTransform createInverse() throws
NoninvertibleTransformException
berechnet die inverse Transformation
09-Transformationen
19
Transformation von Objekten
public
Point2D transform(Point2D ptSrc, Point2D ptDst)
Transformiert den Punkt ptSrc mit der aktuellen Transformation. Das
Ergebnis wird auf das Objekt ptDst gespeichert und als Wert der
Methode zurückgegeben. Ist ptDst==null wird ein neues Objekt
erzeugt.
public void transform(Point2D[] ptSrc, int srcOff,
Point2D[] ptDst, int dstOff, int numPts)
Transformiert einen Vektor ptSrc von Punkten und speichert die
Resultate im Vektor ptDst.
public void transform(float[] srcPts, int srcOff,
float[] dstPts, int dstOff, int numPts)
Die zu transformierenden Punkte werden in dem Vektor srcPtr = {x0,
y0, x1, y0, …} gespeichert. Analog die Resultate in dstPts.
Analoge Methoden für double[]double[], float[]double[]
und double[]float[].
09-Transformationen
20
public
Point2D inverseTransform(Point2D ptSrc,
Point2D ptDst) throws NoninvertibleTransformException
berechnet den invers transformierten Punkt
public void inverseTransform(double[] srcPts,
int srcOff, double[] dstPts, int dstOff, int numPts)
throws NoninvertibleTransformException
berechnet die invers transformierten Punkte
public Point2D deltaTransform(Point2D ptSrc,
Point2D ptDst)
berechnet die Transformation des Punktes ptSrc, wobei die
Translationskomponente nicht berücksichtigt wird.
public void deltaTransform(double[] srcPts,
int srcOff, double[] dstPts, int dstOff, int numPts)
berechnet die Transformation eines Vektors von Punkten ohne
Berücksichtigung der Translationskomponente
09-Transformationen
21
public
Shape createTransformedShape(Shape pSrc)
Berechnet ein Shape-Objekt als Transformation des Shape-Objektes
pSrc. Shape-Objekte sind allgemeine 2D-Objekte in Graphics2D.
09-Transformationen
22
Herunterladen