Vous êtes sur la page 1sur 7

Survol

 Bases
Synthèse d’images  Points
 Vecteurs
Outils mathématiques de base  Lignes
 Sphères
Alexandre Meyer  Matrices et transformations
http://bat710.univ-lyon1.fr/~ameyer/cours

1 Synthèse d’images 2

Maths pour SI (computer graphics) Points, P (x, y, z)


 Besoin mathématiques  Donne une position relative à l’origine
 Décrire la scènes dans notre système de coordonne
 Opérations : projection et transformations
Z
 Système de coordonnée
P(x,y,z)
Y

Right-Handed System Y
(ortho normé)

X X

Z
Synthèse d’images 3 Synthèse d’images 4

Points, P (r,a,b) coordonnées polaires Vecteurs, V (x, y, z)


 Donne une direction dans l’espace 3D

Z  Points != Vecteurs
 Exercice
 Point – Point = Vecteur
P(x,y,z) x=?
 Vecteur+Vecteur = Vecteur
r y=?
a  Point + Vecteur = Point
Y z=?
 Point + Point = ?
b

Synthèse d’images 5 Synthèse d’images 6

1
Vecteurs, V (x, y, z) Vecteurs V
 Longueur (norme) d’un vecteur V (x, y, z)
w  |V| =
v
2v v
(-1)v (1/2)V v+w ^
vecteurV V
Addition de vecteurs  Vecteur unitaire V = normede V = | V |
multiplication par un scalaire v+w
-> vecteurs restent //
 Produit scalaire (Dot Product)
w y
P  a · b = |a| |b| cosθ
v-w Le produit scalaire
v v cosθ = a · b/ |a| |b| est un scalaire
w  a · b = xa ·xb + ya ·yb + za ·zb
Difference de vecteur O  Si les vecteurs sont unitaires?
x
v - w = v + (-w)  Si le produit scalaire == 0 ou == 1?
Vecteur OP
Synthèse d’images 7 Synthèse d’images 8

Produit vectoriel (Cross Product) Plan


 Produit vectoriel -> vecteur normal au 2  3 points non alignés forme un plan unique
vecteurs  Equation : ax+by+cz+d=0
UxV
  Attention : 4 points ne sont pas forcement
V
coplanaire
U

 |a x b| = |a||b|sinθ

Synthèse d’images 9 Synthèse d’images 10

Exercices Exercices
A(1,0,0), B(0,1,0), C(0,0,1) A(1,0,0), B(0,1,0), C(0,0,1)
 Vecteur normal au plan?  Vecteur normal au plan?

 Equation du plan A,B,C?  Calculer ABxBC par exemple


 (-1,1,0)x(0,-1,1) = (1,1,1)
 Equation du plan A,B,C?
 Tous les points P tq
 N.(P-A)=0
 avec N un vecteur normal au plan
 (1,1,1).(x-1,y,z)=0x-1+y+z=0

Synthèse d’images 11 Synthèse d’images 12

2
Equation paramétrique d’une ligne Equation d’une sphère
 Soit hypotenuse
P0 = (x0, y0, z0) et  Théorème de c
 a2 + b2 = c2 b
Pythagore
 P1 = (x1, y1, z1) a
 la ligne P passant par P0 et P1 est  Cercle de rayon,
pour tout P sur le
x(t) = x0 + t(x1 - x0) cercle : P
P(t) = P0 + t(P1 - P0) = y(t) = y0 + t(y1 - y0) r yp
z(t) = z0 + t(z1 - z0) x2 + y2 = r2 (0, 0) xp
avec - ∞ < t < ∞

Si 0<t<1 on a le segment [P0P1]


Synthèse d’images 13 Synthèse d’images 14

Equation d’une sphère Survol


∗Theorème de Pythagor généralisé à la 3D  Bases
a2 + b2 + c2 = d2  Matrices et transformations
x2 + y2 + z2 = r2
 Operations
 Transformations
 Compositions

(x- xc)2 + (y- yc)2 + (z- zc)2 = r2

Synthèse d’images 15 Synthèse d’images 16

Matrices Types de matrices


 Matrices identité - I  Symétrique
 Une Matrice (Matrix) est un tableau de
dimensions M (lignes) par N (colonnes) 1 0 0 0 a b
b d
c
 1 0
 0 1 0 1 0 0 e
 3 par 6 matrice   0 0 1 0 c e f 
 3 0 0 − 2 1 − 2 
 1 1 3 4 1 −1  0 0 0 1
 élément 2,3 est (3)  
−5 2 0 0 0 1 
   Diagonal

1 0 0 0 
 Vecteur peut être considéré comme une 0 2 0 0 
0 0 −1 0 
matrice 1 x M 0 0 0 −4
 
v = (x y z )

Synthèse d’images 17 Synthèse d’images 18

3
Opérations sur les matrices Opérations sur les matrices
 Addition  Multiplication
 Possible seulement si
 x1 par y1 et x2 par y2 SSI y1 = x2
 Résultat : matrice x1 par y2

 Attention : si A x B est possible, cela ne veut pas


 Transpose dire que B x A l’est aussi!!!
 M par N devient N par M
T
 1 4 9  1 5 6 
   
 5 2 8 =  4 2 7 
 6 7 3  9 8 3 
   
Synthèse d’images 19 Synthèse d’images 20

Opérations sur les matrices Exemple de multiplications


* 
 A est n par k , B est k par m 
 * * * * * *
 * 
 *   
  = 
  *   
2 1 
C = A x B est définie par
*

 


 2 3 1 1 −1 =  __ __ 

 −1 0 1  
 0 1   __ __ 
. * 

 * * * * *. *
 . * 
   
k  .*
 =   
cij = ∑ ailblj
 
 . *   
. *   
 
l =1 . *   2 − 2 3  0 0 1   __ __ __ 

 . . . . . .
 * * * * * .
*  . . 
 . * 
 = 
 − 3 1 0  1 0 0 = __ __ __
 1 −1 −1 0 1 0  
*
 
 . *   

 BxA != AxB
.
 *  


    __ __ __ 
Synthèse d’images 21 Synthèse d’images 22

Inverse Transformation 3D
 En 3D, un vecteur est transformé par une
 Si A x B = I et B x A = I alors matrice 3 par 3
A = B-1 et B = A-1  a b c  x   ax + by + cz 
    
 d e f  y  =  dx + ey + fz 
 g h i  z   gx + hy + iz 
    

a d g
 
(x y z ) b e h  = (xa + yb + zc xd + ye + zf xg + yh + zi)
c f i 

ATTENTION : matrice transposée ici


Synthèse d’images 23 Synthèse d’images 24

4
Changement d’échelle Rotation :exercice  ? ? ?
 
 Matrice diagonale  Rotation autour de  ? ? ?
 a 0 0  x   ax l’axe des z  ? ? ?
      
 0 b 0  y  =  by 
 0 0 c  z   cz  Y
     P' = ei(α +θ ) P = (x y)
 Exemple = (r cos(α ) r sin(α ))
θ
 2 0 0  3   6  P = r (cos(α ) + i sin(α ))
     α
 0 1 0  4  =  4  = reiα
 0 0 − 2  5   −10 X
    

Synthèse d’images 25 Synthèse d’images 26

Rotation Y Rotation
P' = ei(α +θ )
 Rotation autour de l’axe des z  Rotation autour de l’axe des z
θ
P
 cos(θ) - sin(θ) 0  Y
P ' = rei (α +θ ) = reiα eiθ α   (cos( θ )x - sin( θ )y sin ( θ )x + cos( θ )y)

X  sin(θ) cos(θ) 0  θ
= ( x + iy )(cos(θ ) + i sin(θ ))  0
 0 1  (x y )
= x cos(θ ) + xi sin(θ ) + iy cos(θ ) + iyi sin(θ ))
 cos(θ ) − sin(θ )  x  X
=   
 sin(θ ) cos(θ )  y  i2=-1
 Car Z ne change pas

 Remarque : Z ne change pas


Synthèse d’images 27 Synthèse d’images 28

Rotation autour de X ou Y Exercice


 Autour de X 1 0 0   Trouver la matrice qui translate un point P?
 
 0 cos(θ) - sin(θ)   x  x + a
 0 sin(θ) cos(θ)     
   P  y P’  y + b 
z  z +c
   
 Autour de Y
 cos(θ ) 0 - sin(θ ) 
 0 1 0  M tq M.P=P’ ?
 sin(θ ) 0 cos(θ ) 


 

Synthèse d’images 29 Synthèse d’images 30

5
Translation avec coord homogène Coordonnées homogène
 Ajoute 1D, mais on la contraint à être égale à 1
(x,y,z,1)
1 0 0 a  x   x + a 
    
0 1 0 b  y   y + b 
Homogène veut dire qu’un point de l’espace 3D
0 = 
0 1 c  z   z + c  peut être représente par une infinité de point
    
0 0 0 1  1   1  homogène 4D

 (2 3 4 1) = (4 6 8 2) = (3 4.5 6 1.5)

 On ajoute une 4e dimension « fictive » que  Pourquoi ceci?


l’on appelle coordonnée homogène  4D permet d’inclure translation/projection dans la
matrice

Synthèse d’images 31 Synthèse d’images 32

Rotation/changement d’échelle puis translation Composition : exercice


Trans suivi d’une Rot / Rot suivie d’une Trans
 R1 R2 R3 T 1 
   P(3,1,0)

 R4 R5 R6 T 2   R=rot(Z,Pi/2)
 R7 R8 R9 T 3  = T.R  T=trans(2,0,0)
 
0 0 0 1  Calculer P’=R.T.P et P”=T.R.P
 

 R= rotation et changement d’échelle


 T = translation

Synthèse d’images 33 Synthèse d’images 34

Composition : exercice Composition


Trans suivi d’une Rot / Rot suivie d’une Trans  L’ordre a de l’importance
 P(3,1,0)  Trans suivi d’une rot != rot suivie d’une trans
 R=rot(Z,Pi/2)  (RT)v != (TR)v
 T=trans(2,0,0)
v1
 Calculer P’=R.T.P et P”=T.R.P v1
 P’ = R.T.P = R.(5,1,0) = (-1,5,0) v v2
v
 P”=T.R.P = T.(-1,3,0) = (1,3,0)

 P’ != P”

T puis R = R.T.v=v1 R puis T = T.R.v = v2

Synthèse d’images 35 Synthèse d’images 36

6
Rotation de l’objet Programmation OpenGL
 Pour faire une rotation de l’objet  OpengGL
mat[0] mat[1] mat[2] mat[3]
GLfloat mat[16]; mat[4] mat[5] mat[6] mat[7]
mat[8] mat[9] mat[10] mat[11]
mat[12] mat[13] mat[14] mat[15]

 glRotate( ax, ay, az, angle);

 glTranslate( x, y, z);

 glScale( sx, sy, sz);

Synthèse d’images 37 Synthèse d’images 38

Ouf!!! …
 On a la base …

Synthèse d’images 39

Vous aimerez peut-être aussi