Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung...

26
Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

Transcript of Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung...

Page 1: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

Institut für Kartographie und GeoinformationProf. Dr. Lutz Plümer

Diskrete Mathematik I

Vorlesung 3

28.10.99

-Arrays-

Page 2: Institut für Kartographie und Geoinformation Prof. 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

Page 3: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

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

Page 4: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

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 */

Page 5: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

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

Page 6: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

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

Page 7: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

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

Page 8: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

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

Page 9: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

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

Page 10: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

10

Px

y

Punkte als Arrays

P p x yx

y: ( )

Page 11: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

11

Verschiebung (Translation)

t

Px

y

P p x yx

y: ( )

Page 12: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

12

Verschiebung (Translation)

P

t

x

y

P p x yx

y': ' ( ' ')

'

'

Page 13: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

13

Verschiebung (Translation)

Px

y

tyt

tx

p p t

x

y

x

y

t

t

x t

y tx

y

x

y'

'

'

Page 14: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

14

P

Drehung (um den Ursprung)

x

y

Page 15: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

15

Drehung (um den Ursprung)

P

x

y

Page 16: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

16

Drehung (um den Ursprung)

cossin

sincos

cossin

sincos

'

'

yx

yx

y

x

y

x

P

x

y

p R p'

Page 17: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

17

2 8

2

6

Scherung (Zoom in, Zoom out)

P

x

y

Page 18: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

18

3

9

4 16

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

Page 19: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

19

P

homogene Koordinaten

Homogene Koordinaten

Px

y:

P

x

y:

1

x

y

Page 20: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

20

Translation in homogenen Koordinaten

100

10

01

: y

x

t

t

T

Px

y

tyt

tx

t

t

tx

y:

Page 21: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

21

11100

10

01

1

'

'

y

x

y

x

ty

tx

y

x

t

t

y

x

Translation in homogenen Koordinaten

Px

y

tyt

tx

Page 22: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

22

Drehung in homogenen Koordinaten

R:cos sin

sin cos

100

0cossin

0sincos

:

R

P

x

y

Page 23: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

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

x

y

Drehung in homogenen Koordinaten

Page 24: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

24

Scherung in homogenen Koordinaten

y

x

s

sS

0

0 :

100

00

00

: y

x

s

s

S

sx P´

x

ysy

Page 25: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

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

Page 26: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik I Vorlesung 3 28.10.99 -Arrays-

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