1
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Ripasso: prodotto scalare e vettoriale
• Prodotto Vettoriale ("cross-product", "external product") : vettore x vettore → vettore
0 ) ( ) (
) (
=
⋅
×
=
⋅
×
×
−
=
×
u v u v v u
u v v u Proprietà
il risultato è ortogonale ad entrambi gli operandi:
non commuta:
−
−
−
=
×
x y y x
z x x z
y z z y z y x z y x
β α β α
β α β α
β α β α β β β α α
α , , ) ( , , )
(
u v u x v
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Ripasso: prodotto scalare e vettoriale
• Prodotto Vettoriale ("cross-product", "external product") : vettore x vettore → vettore
Proprietà
−
−
−
=
×
x y y x
z x x z
y z z y z y x z y x
β α β α
β α β α
β α β α β β β α α
α , , ) ( , , )
(
θ θ
sen 0
sen
=
×
⇔
=
×
=
×
v u
v u v u
v u v u
e allineati e, se u e v
sono normalizzati:
quindi se u e v non sono nulli:
molto utilmente:
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Spazio affine
• Tre entità – scalari – vettori – punti
attributi:
lunghezza, direzione unico attributo:
la posizione, rispetto ad un sistema di riferimento
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Spazio affine
• Tre entità – scalari – vettori – punti
• Operazioni:
– Eredita dallo (è uno) spazio vettoriale:
• Somma e prodotto tra scalari
• Moltiplicazione (scalare ,,,, vettore )→ vettore
• Somma (vettore ,,,, vettore) → vettore – Somma (punto ,,,, vettore ) → punto – Sottrazione (punto ,,,, punto) → vettore
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Sistema di riferimento ( frame )
• Definito da
– un punto base (origine) p
0– e una base vettoriale { v
0, v
1, v
2}
• Posso esprimere (univocamente) ogni punto punto punto punto p come:
p = v 0 η 0 + v 1 η 1 + v 2 η 2 + p 0
coordinate omogenee di p lin indip
• cioè: p = v 0 v 1 v 2 p 0 η 0 η 1 η 2 1
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Sistema di riferimento ( frame )
• Definito da
– un punto base (origine) p
0– e una base vettoriale { v
0, v
1, v
2}
• Posso esprimere (univocamente) ogni vettore vettore vettore vettore v come:
v = v 0 η 0 + v 1 η 1 + v 2 η 2 + p 0
coordinate omogenee di p
• cioè: v = v 0 v 1 v 2 p 0
η 0
η 1
η 2
0
2
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Sistema di riferimento ( frame )
• Un frame può essere:
– ortogonale
(se i vettori della base lo sono fra loro) – ortonormale
(se i vettori della base sono ortogonali e normali)
• Frame canonico:
– matrice identità
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Chiralità di un frame
• Un sistema di riferimento ortogonale può essere immaginato sinistrorso o destrorso
sinistrorso destrorso
z y x × =
• Ricordiamoci di usare la STESSA MANO per immaginare il prodotto cross
z y x × = comunque!
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Rappresentazione di punti e vettori in coordinate omogenee
= 1
3 2 1
α α α p
= 0
3 2 1
δ δ δ a
Punti Vettori
1 0
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
q = (p) v = (u) Trasformazioni
• Funzioni
input: un punto (o un vettore)
output: un punto (o vettore)
– ci interessano
trasformazioni che siano lineari:
p
f f f
f
q
f
) ( ) ( )
( v
0v
1f v
0f v
1f α + β = α + β (coi vettori)
) ( ) ( )
( p v f p f v
f + α = + α (coi punti)
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Trasformazioni Affini
• Sono lineari e dunque preservano:
– la colinearità
• tutti i punti
inizialmente su una linea giacciono ancora su di una linea dopo la trasformazione
e anche – i rapporti tra le distanze
• il punto di mezzo di un segmento rimane il punto di mezzo di un segmento anche dopo la trasformazione.
in generale non in generale non in generale non in generale non preservano:
preservano: preservano:
preservano:
distanze, angoli, aree se lo fanno, le
chiamiamo
“trasf. Rigide”
“isometrie” o
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Trasformazioni Affini
• Si possono esprimere come moltiplicazione con matrice
sempre
=
1 1 0 0 0 1
3 2 1
34 33 32 31
24 23 22 21
14 13 12 11
3 2 1
γ γ γ
α α α α
α α α α
α α α α
γ γ γ f
coordinate affini punto di partenza
= 1
3 2 1
δ δ δ
coordinate affini
punto di arrivo
3
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
conta solo questo
Trasformazioni Affini
• Caso vettori
sempre
=
1 1 0 0 0 1
3 2 1
34 33 32 31
24 23 22 21
14 13 12 11
3 2 1
γ γ γ
α α α α
α α α α
α α α α
γ γ γ f
coordinate affini vettore di partenza
= 1
3 2 1
δ δ δ
coordinate affini vettore di arrivo
0000 0000 ... ... ... ... 0000
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Esempio: trasformazione di traslazione rigida
+
=
′
′
′
0 1 1
z y x
z y x
z y x
α α α
=
1 1 0 0 0
1 0 0
0 1 0
0 0 1
1
z y x
z y x f
z y x
α α α posso riscriverla come:
e cioè:
+ + +
=
1 1
z y x
z y x
z y x
f α
α α
vettore di traslazione
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Trasformazione di Traslazione rigida
l'inversa è ovviamente:
=
1 0 0 0
1 0 0
0 1 0
0 0 1 ) , , (
z y x
z y
x
α
α α α
α α T
−
−
−
=
−
−
−
−
=
1 0 0 0
1 0 0
0 1 0
0 0 1 ) , , ( ) , ,
1
(
z y x
z y x z y
x
α
α α α
α α α α
α T
T
matrice di traslazione:
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Trasformazione di Traslazione rigida
cosa succede se la applico ad un vettore ?
=
1 1 0 0 0
1 0 0
0 1 0
0 0 1
0
z y x
z y x f
z y x
α α α
0000 0000
= 0 z y x
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
(γ ) S
matrice di scaling matrice di scaling matrice di scaling matrice di scaling
Trasformazione di Scalatura uniforme
x y x
y
=
1 1
z y x
z y x
f γ
γ γ
=
1 1 0 0 0
0 0 0
0 0 0
0 0 0
1
z y x
z y x
f γ
γ γ
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Trasformazione di Scalatura generica
x y x
y
=
1 1
z y x
z y x f
z y x
γ γ γ
) , , ( γ
xγ
yγ
zS
matrice di scaling matrice di scaling matrice di scaling matrice di scaling
=
1 1 0 0 0
0 0 0
0 0 0
0 0 0
1
z y x
z y x f
z y x
γ γ γ
inversa?
4
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Trasformazione di Scalatura generica
x y
x y
nota: la scalatura applicata ai punti
"scala" anche la distanza dall'origine
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Trasformazione di Scalatura generica
• Osservazioni :
– Fattori di scala inferiori a 1 avvicinano l’oggetto al punto fisso di riferimento (origine)
– Fattori di scala maggiori di 1 lo allontanano – Se s x ≠ s y o s y ≠ s z le proporzioni dell’oggetto non
sono mantenute (scalatura non uniforme, o anisotropica )
– Se s x = s y = s z le proporzioni sono mantenute e si ha una scalatura uniforme (o isotropica )
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Shearing
• Lo spostamento proporzionale alla pos y
=
=
′
′ = +
=
′
1 0 0 0
0 1 0 0
0 0 1 0
0 0 cot 1 ) (
cot
θ θ
θ
H
xyz z
y y
y x x
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Rotazione attorno all'asse z
(x’,y’)
(x,y)
x y
z
φ ρ
φ ρ
sin cos
=
= y x
partenza:
) sin(
) cos(
θ φ ρ
θ φ ρ
+
=
′
+
′ = y
arrivo: x
ρ φ
θ
θ θ
θ θ
cos sin
sin cos
y x
y x
+
=
−
= θ φ ρ θ φ ρ
θ φ ρ θ φ ρ
cos sin sin cos
sin sin cos cos
+
=
−
=
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Rotazione attorno all'asse z
(x’,y’)
(x,y)
x y
z
ρ φ
θ θ
θ θ θ
cos sin '
sin cos
y x y
y x x
+
=
−
=
′
=
1 0 0 0
0 1 0 0
0 0 cos sin
0 0 sin - cos )
( θ θ
θ θ
Z
θ R
= +
=
′
′
′
1 cos sin
sin - cos
1 ) ( 1
z y x
y x
z y x z R
y x
Z
θ θ
θ θ θ
M a r c o T a r i n i ‧ C o m p u t e r G r a p h i c s ‧ 2 0 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Rotazione attorno all'asse x, y, o z
=
1 0 0 0
0 1 0 0
0 0 cos sin
0 0 sin - cos )
( θ θ
θ θ
Z
θ R
=
1 0 0 0
0 cos sin 0
0 sin - cos 0
0 0 0 1 )
( θ θ
θ θ θ
R
X
=
1 0 0 0
0 cos 0 sin -
0 0 1 0
0 sin 0 cos )
( θ θ
θ θ
Y
θ R
e le inverse?
T
1
( ) ( )
)
( θ
Xθ
Xθ
X