10.06.2013 Views

Trasformazioni nello spazio Grafica 3d

Trasformazioni nello spazio Grafica 3d

Trasformazioni nello spazio Grafica 3d

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><br />

<strong>Grafica</strong> <strong>3d</strong><br />

Giancarlo RINALDO<br />

rinaldo@dipmat.unime.it<br />

Dipartimento di Matematica<br />

Università di Messina<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 1


Introduzione<br />

In questa lezione estenderemo quanto detto nella<br />

precedente lezione allo <strong>spazio</strong> a 3 dimensioni.<br />

In particolare<br />

I punti in coordinate omogenee avranno 4 coordinate<br />

(x,y,z, 1);<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 2


Introduzione<br />

In questa lezione estenderemo quanto detto nella<br />

precedente lezione allo <strong>spazio</strong> a 3 dimensioni.<br />

In particolare<br />

I punti in coordinate omogenee avranno 4 coordinate<br />

(x,y,z, 1);<br />

Alle trasformazioni saranno associate matrici 4 × 4.<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 2


Introduzione<br />

In questa lezione estenderemo quanto detto nella<br />

precedente lezione allo <strong>spazio</strong> a 3 dimensioni.<br />

In particolare<br />

I punti in coordinate omogenee avranno 4 coordinate<br />

(x,y,z, 1);<br />

Alle trasformazioni saranno associate matrici 4 × 4.<br />

La rappresentazione su un piano dovrà essere<br />

effettuata tramite una proiezione.<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 2


Introduzione<br />

In questa lezione estenderemo quanto detto nella<br />

precedente lezione allo <strong>spazio</strong> a 3 dimensioni.<br />

In particolare<br />

I punti in coordinate omogenee avranno 4 coordinate<br />

(x,y,z, 1);<br />

Alle trasformazioni saranno associate matrici 4 × 4.<br />

La rappresentazione su un piano dovrà essere<br />

effettuata tramite una proiezione.<br />

In un primo momento visualizzeremmo sul nostro<br />

schermo solo le coordinate x, y, scartando la z,<br />

successivamente considereremo le proiezioni.<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 2


Orientamento<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 3


Orientamento<br />

Nel proseguio considereremo il nostro <strong>spazio</strong> in un<br />

sistema di coordinate cartesiane ortogonali, cioè tali che<br />

x ⊥ y, x ⊥ z, y ⊥ z.<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 3


Orientamento<br />

Nel proseguio considereremo il nostro <strong>spazio</strong> in un<br />

sistema di coordinate cartesiane ortogonali, cioè tali che<br />

x ⊥ y, x ⊥ z, y ⊥ z.<br />

Inoltre orienteremo i nostri assi nel seguente modo: se x<br />

e y sono disegnati nel modo “standard” sul nostro<br />

schermo, allora l’asse z sarà perpendicolare al piano<br />

(schermo) ed uscente nella nostra direzione.<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 3


Orientamento<br />

Nel proseguio considereremo il nostro <strong>spazio</strong> in un<br />

sistema di coordinate cartesiane ortogonali, cioè tali che<br />

x ⊥ y, x ⊥ z, y ⊥ z.<br />

Inoltre orienteremo i nostri assi nel seguente modo: se x<br />

e y sono disegnati nel modo “standard” sul nostro<br />

schermo, allora l’asse z sarà perpendicolare al piano<br />

(schermo) ed uscente nella nostra direzione.<br />

Analogamente possiamo usare la regola della “mano<br />

destra” : si punta il pollice nella direzione dell’asse x,<br />

l’indice in quella dell’asse y, il medio dà la direzione<br />

dell’asse z.<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 3


Traslazione <strong>nello</strong> <strong>spazio</strong><br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 4


Traslazione <strong>nello</strong> <strong>spazio</strong><br />

I punti <strong>nello</strong> <strong>spazio</strong> xyz possono essere “traslati” in una<br />

nuova posizione aggiungendo le quantità, Tx, Ty, Tz, cioè<br />

considerando la trasformazione:<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 4


Traslazione <strong>nello</strong> <strong>spazio</strong><br />

I punti <strong>nello</strong> <strong>spazio</strong> xyz possono essere “traslati” in una<br />

nuova posizione aggiungendo le quantità, Tx, Ty, Tz, cioè<br />

considerando la trasformazione:<br />

(x ′ ,y ′ ,z ′ , 1) =<br />

⎛<br />

⎜<br />

⎝<br />

1 0 0 Tx<br />

0 1 0 Ty<br />

0 0 1 Tz<br />

0 0 0 1<br />

⎞<br />

⎟<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

x<br />

y<br />

z<br />

1<br />

⎞<br />

⎟<br />

⎠<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 4


Traslazione <strong>nello</strong> <strong>spazio</strong><br />

I punti <strong>nello</strong> <strong>spazio</strong> xyz possono essere “traslati” in una<br />

nuova posizione aggiungendo le quantità, Tx, Ty, Tz, cioè<br />

considerando la trasformazione:<br />

(x ′ ,y ′ ,z ′ , 1) =<br />

⎛<br />

⎜<br />

⎝<br />

1 0 0 Tx<br />

0 1 0 Ty<br />

0 0 1 Tz<br />

0 0 0 1<br />

Ovviamente l’applicazione di una traslazione di Tz unità,<br />

non ha effetto “apparente” sul nostro schermo.<br />

⎞<br />

⎟<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

x<br />

y<br />

z<br />

1<br />

⎞<br />

⎟<br />

⎠<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 4


Scala<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 5<br />

.


Scala<br />

Anche i punti <strong>nello</strong> <strong>spazio</strong> possono essere “scalati”<br />

(stirati/accorciati) di un fattore Sx lungo l’asse x, di un<br />

fattore Sy lungo l’asse y e di un fattore Sz lungo l’asse z.<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 5


Scala<br />

Anche i punti <strong>nello</strong> <strong>spazio</strong> possono essere “scalati”<br />

(stirati/accorciati) di un fattore Sx lungo l’asse x, di un<br />

fattore Sy lungo l’asse y e di un fattore Sz lungo l’asse z.<br />

La trasformazione è data da:<br />

(x ′ ,y ′ ,z ′ , 1) =<br />

⎛<br />

⎜<br />

⎝<br />

Sx 0 0 0<br />

0 Sy 0 0<br />

0 0 Sz 0<br />

0 0 0 1<br />

⎞<br />

⎟<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

x<br />

y<br />

z<br />

1<br />

⎞<br />

⎟<br />

⎠<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 5


Scala<br />

Anche i punti <strong>nello</strong> <strong>spazio</strong> possono essere “scalati”<br />

(stirati/accorciati) di un fattore Sx lungo l’asse x, di un<br />

fattore Sy lungo l’asse y e di un fattore Sz lungo l’asse z.<br />

La trasformazione è data da:<br />

(x ′ ,y ′ ,z ′ , 1) =<br />

⎛<br />

⎜<br />

⎝<br />

Sx 0 0 0<br />

0 Sy 0 0<br />

0 0 Sz 0<br />

0 0 0 1<br />

Anche in questo caso l’applicazione di una scala Sz, non<br />

ha effetto “apparente” sul nostro schermo.<br />

⎞<br />

⎟<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

x<br />

y<br />

z<br />

1<br />

⎞<br />

⎟<br />

⎠<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 5


Scala<br />

Anche i punti <strong>nello</strong> <strong>spazio</strong> possono essere “scalati”<br />

(stirati/accorciati) di un fattore Sx lungo l’asse x, di un<br />

fattore Sy lungo l’asse y e di un fattore Sz lungo l’asse z.<br />

La trasformazione è data da:<br />

(x ′ ,y ′ ,z ′ , 1) =<br />

⎛<br />

⎜<br />

⎝<br />

Sx 0 0 0<br />

0 Sy 0 0<br />

0 0 Sz 0<br />

0 0 0 1<br />

Anche in questo caso l’applicazione di una scala Sz, non<br />

ha effetto “apparente” sul nostro schermo.<br />

⎞<br />

⎟<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

x<br />

y<br />

z<br />

1<br />

⎞<br />

⎟<br />

⎠<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 5


Rotazione Rz<br />

La rotazione in 2D non è altro che la rotazione rispetto<br />

all’asse z, Rz. Dunque essa avrà la forma:<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 6


Rotazione Rz<br />

La rotazione in 2D non è altro che la rotazione rispetto<br />

all’asse z, Rz. Dunque essa avrà la forma:<br />

(x ′ ,y ′ ,z ′ ⎛<br />

⎞ ⎛ ⎞<br />

cos θ − sinθ 0 0 x<br />

⎜<br />

, 1) = ⎜ sinθ<br />

⎝ 0<br />

cos θ<br />

0<br />

0 0 ⎟ ⎜<br />

⎟ ⎜ y ⎟<br />

1 0 ⎠ ⎝ z ⎠<br />

0 0 0 1 1<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 6


Rotazioni Rx, Ry<br />

La rotazione rispetto all’asse x, Rx, sarà:<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 7


Rotazioni Rx, Ry<br />

La rotazione rispetto all’asse x, Rx, sarà:<br />

(x ′ ,y ′ ,z ′ ⎛<br />

1 0 0 0<br />

⎜<br />

, 1) = ⎜ 0 cosθ − sin θ 0<br />

⎝ 0 sin θ cosθ 0<br />

0 0 0 1<br />

⎞<br />

⎟<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

x<br />

y<br />

z<br />

1<br />

⎞<br />

⎟<br />

⎠<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 7


Rotazioni Rx, Ry<br />

La rotazione rispetto all’asse x, Rx, sarà:<br />

(x ′ ,y ′ ,z ′ ⎛<br />

1 0 0 0<br />

⎜<br />

, 1) = ⎜ 0 cosθ − sin θ 0<br />

⎝ 0 sin θ cosθ 0<br />

0 0 0 1<br />

La rotazione rispetto all’asse y, Ry, sarà:<br />

(x ′ ,y ′ ,z ′ , 1) =<br />

⎛<br />

⎜<br />

⎝<br />

cosθ 0 sinθ 0<br />

0 1 0 0<br />

− sin θ 0 cos θ 0<br />

0 0 0 1<br />

⎞<br />

⎟<br />

⎠<br />

⎞<br />

⎟<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

⎛<br />

⎜<br />

⎝<br />

x<br />

y<br />

z<br />

1<br />

x<br />

y<br />

z<br />

1<br />

⎞<br />

⎟<br />

⎠<br />

⎞<br />

⎟<br />

⎠<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 7


Una traslazione utile<br />

Proviamo ad effettuare la seguente traslazione<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 8


Una traslazione utile<br />

Proviamo ad effettuare la seguente traslazione<br />

(x ′ ,y ′ ,z ′ ⎛ ⎞ ⎛<br />

1 0 0 −3 x<br />

⎜<br />

, 1) = ⎜ 0 1 0 −3 ⎟ ⎜<br />

⎟ ⎜ y<br />

⎝ 0 0 1 4 ⎠ ⎝ z<br />

0 0 0 1 1<br />

⎞<br />

⎟<br />

⎠<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 8


Esercizi<br />

Ruotare la casa rispetto al suo centro di simmetria<br />

tramite Rx, Ry ed Rz;<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 9


Esercizi<br />

Ruotare la casa rispetto al suo centro di simmetria<br />

tramite Rx, Ry ed Rz;<br />

Ruotare la casa rispetto ad un suo lato (che dunque<br />

giace su un asse di rotazione);<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 9


Esercizi<br />

Ruotare la casa rispetto al suo centro di simmetria<br />

tramite Rx, Ry ed Rz;<br />

Ruotare la casa rispetto ad un suo lato (che dunque<br />

giace su un asse di rotazione);<br />

Scalare la casa rispetto al suo centro di simmetria;<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 9


Esercizi<br />

Ruotare la casa rispetto al suo centro di simmetria<br />

tramite Rx, Ry ed Rz;<br />

Ruotare la casa rispetto ad un suo lato (che dunque<br />

giace su un asse di rotazione);<br />

Scalare la casa rispetto al suo centro di simmetria;<br />

“Tentare” di visualizzare la profondità della casa.<br />

<strong>Trasformazioni</strong> <strong>nello</strong> <strong>spazio</strong><strong>Grafica</strong> <strong>3d</strong> – p. 9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!