Upload
lene-wessling
View
103
Download
0
Embed Size (px)
Citation preview
Institut für Kartographie und GeoinformationProf. Dr. Lutz Plümer
Diskrete Mathematik I
Vorlesung 3
28.10.99
-Arrays-
2
Übersicht
• Arrays (am Beispiel von Java)• Unterschiede in der Verwendung primitiver Datentypen/Arrays• Arrays - beachte• Zugriff• Beispiele
– Skalarprodukt
– Multiplikation von Matrizen
• Punkte als Arrays• Transformationen• Homogene Koordinaten
– Transformationen
3
Arrays (am Beispiel von Java)
Unterscheidungen• primitive Datentypen:
– booleanchar byte short int long float1 2 1 2 4 8 4Byte
– Größe steht von vorneherein fest
• Referenztypen– Arrays– Strings– Objekte– Größe erst zur Laufzeit bekannt
4
Unterschiede in der Verwendung primitiver Typen / Arrays
Primitive Typen
int i, j; // Deklaration
i = 0; // Initialisierung
j = 1;
oder:
int i = 0, j = 1;
/* Deklaration und Initialisierung gleichzeitig */
Arrays
int a[], b[]; // int - Array
float v[], w[]; // float- Array
float m1[][];// float - Matrix
a = new int[5]; // Erzeugungw = new float[3];m1 = new float[3][3];
oder:int b[] = {1,2,3,4,5};/* Deklaration, Erzeugung und Initialisierung gleichzeitig */
5
Arrays - beachte:
• 3 Schritte– Deklarieren– Erzeugen (Instanz bilden, Instanziieren)– Initialisierungen
• Im Unterschied zu Pascal– die Größe n des Arrays wird erst zum Zeitpunkt der
Erzeugung (new double[3] ) festgelegt
• Die Indizierung läuft von 0 ... n - 1
0 n -1
6
Zugriff
int a[][] = new int[2][3];
a[0][0] = 1;
a[0][1] = 2;
a[0][2] = 3;
a[1][0] = 4;
a[1][1] = 5;
a[1][2] = 6;
654
321
7
Beispiel: Skalarprodukt
int v[], w[];
v = {1,2,3};
w = {4,5,6};
int iprod = 0;
for (int i = 0; i < 3; i++)
iprod = iprod + v[i] * w[i];
for-Schleife
for(init; test; update)
i++ i = i + 1
8
222120
121110
020100
222120
121110
020100
bbb
bbb
bbb
aaa
aaa
aaa
01c
=c[i,k]= a[i,j]*b[j,k]
Beispiel: Multiplikation von Matrizen
9
float a[][], b[][], c[][];
..
float c[][] = {{0,0,0}, {0,0,0}, {0,0,0}};
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
for (int k = 0; k < 3; k++)
c[i][j] = c[i][j] +
a[i][k] *
b[k][j];
Beispiel: Multiplikation von Matrizen
10
Px
y
Punkte als Arrays
P p x yx
y: ( )
11
Verschiebung (Translation)
t
Px
y
P p x yx
y: ( )
12
P´
Verschiebung (Translation)
P
t
x
y
P p x yx
y': ' ( ' ')
'
'
13
Verschiebung (Translation)
P´
Px
y
tyt
tx
p p t
x
y
x
y
t
t
x t
y tx
y
x
y'
'
'
14
P
Drehung (um den Ursprung)
x
y
15
P´
Drehung (um den Ursprung)
P
x
y
16
Drehung (um den Ursprung)
cossin
sincos
cossin
sincos
'
'
yx
yx
y
x
y
x
P´
P
x
y
p R p'
17
2 8
2
6
Scherung (Zoom in, Zoom out)
P
x
y
18
3
9
4 16
P´
Scherung (Zoom in, Zoom out)
sx x
ysy
p S p
x
y
s
s
x
y
s x
s yx
y
x
y'
'
'
0
0
19
P
homogene Koordinaten
Homogene Koordinaten
Px
y:
P
x
y:
1
x
y
20
Translation in homogenen Koordinaten
100
10
01
: y
x
t
t
T
P´
Px
y
tyt
tx
t
t
tx
y:
21
11100
10
01
1
'
'
y
x
y
x
ty
tx
y
x
t
t
y
x
Translation in homogenen Koordinaten
P´
Px
y
tyt
tx
22
Drehung in homogenen Koordinaten
R:cos sin
sin cos
100
0cossin
0sincos
:
R
P´
P
x
y
23
x
y
x
y
x y
x y
'
'
cos sin
sin cos
cos sin
sin cos
1
0
0
0 0 1 1 1
P´
P
x
y
Drehung in homogenen Koordinaten
24
Scherung in homogenen Koordinaten
y
x
s
sS
0
0 :
100
00
00
: y
x
s
s
S
sx P´
x
ysy
25
Scherung in homogenen Koordinaten
11100
00
00
1
'
'
ys
xs
y
x
s
s
y
x
y
x
y
x
sx P´
x
ysy
Homogene Koordinaten
• Repräsentation in homogenen Koordinaten führt zu „homogener“ Modellierung der Operationen
• Implementierung der Matrizenmultiplikation in Hardware bringt Effizienz
2D 3 x 3 - Matrix
3D 4 x 4 - Matrix