0% found this document useful (0 votes)
5 views63 pages

2IV60 2 Base Math

The document provides an overview of basic mathematical concepts used in computer graphics, focusing on coordinates, points, and vectors in n-dimensional space. It covers various coordinate systems, vector operations, and transformations, emphasizing their applications in computer graphics. Additionally, it introduces matrices as essential tools for defining coordinate frames and transformations.

Uploaded by

shivsahana3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views63 pages

2IV60 2 Base Math

The document provides an overview of basic mathematical concepts used in computer graphics, focusing on coordinates, points, and vectors in n-dimensional space. It covers various coordinate systems, vector operations, and transformations, emphasizing their applications in computer graphics. Additionally, it introduces matrices as essential tools for defining coordinate frames and transformations.

Uploaded by

shivsahana3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 63

2IV60 Computer Graphics

Basic Math for CG


Jack van Wijk
TU/e
Overview
• Coordinates, points, vectors
• Matrices

H&B A-1
nD Space
nD Space: n (typically)
n : number of dimensions
Examples:
• 1D space: time, along a line or curve
• 2D space: plane, sphere
• 3D space: the world we live in
• 4D space: 3D + time
H&B A-2
Coordinates
2D Cartesian coordinates:
x

y (x,y) (x,y)

x
Standard Screen (output, input)
H&B A-1
Polar coordinates
Coordinate transformation
from (r , ) to ( x, y ) space :
y (x,y) x r cos
r y r sin 

Angle  : in radians
x

H&B A-1
3D coordinates 1
3D Cartesian coordinates:

z (x,y,z) z (x,y,z)

y x
x y

Right-handed Left-handed
H&B A-1
3D coordinates 2
3D Cartesian coordinates:

z (middle) (x,y,z) z (middle) (x,y,z)

x (thumb) y (index) x (thumb)


y (index)

Right-handed Left-handed
H&B A-1
3D coordinates 3
Cylinder coordinates:

z (x,y,z) x r cos 
y r sin 
y
z z
x 

H&B A-1
3D coordinates 4
Spherical coordinates: x r cos sin 
y r sin  sin 
z r cos 
z (x,y,z)

r  : azimuth or longitude
y  : elevation or latitude
x 

Also :   / 2  
 : colatitude H&B A-1
Points
• Point: position in nD space
• Notation: P (H&B), also P, p, p en p
• (x,y,z) (H&B), also (x1, x2, x3), (Px, Py, Pz),
(r, , z), ( r, , ), …

H&B A-2
Vectors 1
• Vector:
– “arrow”
– multiple interpretations (displacement, velocity,
force, …)
– has a magnitude and direction
– has no position
• Notation: V (H&B), also V, v, v en v
• (Vx, Vy, Vz) (H&B), also (x, y, z), (x1, x2, x3)
H&B A-2
Vectors 2
V P2  P1
y
P2 ( x2  x1 , y2  y1 )
y2
(Vx , V y )
P1
y1
V: directed line segment, or
difference between two points

x1 x2 x
H&B A-2
Vectors 3
Length of a vector:
V  Vx2  V y2 (2D : Pythagoras)

V  Vx2  V y2  Vz2 (3D)

H&B A-2
Vectors 4
Direction of a vector: Direction angles.
Vx Vy Vz
cos   , cos   , cos   z
V V V 
Unit vector V : 
V y
V x 
|V|
Magnitude info is removed, direction is kept.
H&B A-2
Vector addition
Add components, put vector head to tail

y W y V+W
W
V
V
x x

V  W (Vx  Wx ,V y  W y , Vz  Wz )
H&B A-2
Scalar multiplication of vector
Multiplication components with scalar s

y y
2V
V

x x

sV ( sVx ,sV y , sVz )


H&B A-2
Combining vector operations
Infinite line through P with direction V:
L(t) = P + Vt, t 

y V
P t

t : parameter along line


t [a, b]: line segment H&B A-2
Vector multiplication 1
Scalar product or dot product:
Product of parallel components, gives 1 real value

V V W  V W cos

 VxWx  V yW y  VzWz


|W| cos 
|V|

H&B A-2
Vector multiplication 2
Scalar product:

V W  V W cos
VxWx  V yW y  VzWz
Commutative : V W W V
Distributive : V (W  Z) V W  V Z

Associative : V (W Z) (V W ) Z ??


H&B A-2
Vector multiplication 3
Vector product or cross product: gives a vector (in 3D)

n perpendicular to V and W

V W n V W sin
VW (V yWz  VzW y ,
W VzWx  VxWz ,


VxW y  V yWx )
n V

H&B A-2
Vector multiplication 5

Scalar product:

Anticommutative : V W  W V
Not associative : V (W Z) (V W ) Z
Distributive : V (W  Z) V W  V Z

H&B A-2
Vector multiplication 6
Scalar product: Vector product:
• scalar • vector
• Test if vectors are • Get a vector
perpendicular perpendicular to two
given vectors
• cos • sin
• project,… • surface area,…

H&B A-2
Exercise 1
• Given a point P.
• Requested: Reflect a point Q with respect to P.

Q W=P–Q
W P Q’ = Q + 2W
y
W
Q’
= 2P – Q
or: = P + (P – Q )
x We don’t need coordinates!
Exercise 1
• Given a point P.
• Requested: Reflect a point Q with respect to P.

Q Alternative
P P is halfway Q and Q’:
Q’
P = (Q + Q’)/2
2P = Q + Q’
Q’ = 2P – Q
Exercise 2
• Given a line L: L(t) = P + Vt .
• Requested: Reflect a point Q with respect to L.

Q We know:
W Q’ = Q + 2 W
V L(t)
y P W W = L(t) – Q
t Q’
W. V = 0
x
Exercise 2
We know: Substitute to get t:
L(t) = P + Vt (L(t) – Q).V = 0
Q’ = Q + 2 W (P + Vt – Q).V = 0
W = L(t) – Q V .V t + (P – Q).V = 0
W. V = 0 t = ((Q – P).V) / (V .V)
Then:
Q’ = Q + 2 (P + Vt – Q)
= 2P – Q + 2V((Q – P).V / V .V)
Steps to be made
• Write down what you know
• Eliminate, substitute, etc. to get he result
• Check the result
– Does it make sense?
– Is there a simpler derivation?
Exercise 3
• Given a triangle with vertices P, Q en R,
where the angle PQR is perpendicular.
• Requested: Rotate the triangle around the
line PQ over an angle What is the new
position R’ of R? P

Q R’

R
Circle in space
y
C() C()
r 
B B
 A
P A x P

|A|=1, |B|=1, A.B = 0


C() = (r cos , r sin , 0)
= (0,0,0) + r cos  (1,0,0) + r sin  (0,1,0)
= P + r cos  A + r sin  B
Exercise 3
A = (R – Q) / |R – Q|
B = (R – Q)(P – Q) / | (R – Q)(P – Q) |
R’ = Q + |R – Q| cos  A + |R – Q| sin  B

P
B
Q R’

A
R
Use:
• Scalar product, cross product
• coordinate independent definitions
• vector algebra
Don’t use:
• arccos, arcsin
• y = f(x)
Very short intro to Linear Algebra
System of linear equations:

Such systems occur in many, many applications.


They are studied in Linear Algebra.

u 2 x  3 y  4 z
v x  5 y  3z
w 5 x  y  z

H&B A-5
Very short intro to Linear Algebra
System of linear equations:

Typical questions:
- Given u, v, w, what are x, y, z?
- Can we find a unique solution?

u 2 x  3 y  4 z
v x  5 y  3z
w 5 x  y  z

H&B A-5
Very short intro to Linear Algebra
System of linear equations:

Crucial in computer graphics:


- Transforming geometric objects
- Change of coordinates

u 2 x  3 y  4 z
v x  5 y  3z
w 5 x  y  z

H&B A-5
Example transformation
Transformation P  P ':
y
P : ( x, y ) P: (x,y)
P ' xU  yV , with x

U (3,2)
y’
V ( 2 ,3)
P’
In coordinates : V
x'  3x  2 y U
y x
y '  2 x  3 y x’

H&B A-5
What is a matrix?
Matrix:
- Mathematical objects with operations

Matrix in computer graphics:


- Defines a coordinate frame
- Defines a transformation
- Handy tool for manipulating transformations

H&B A-5
Matrix
Matrix: rectangular array of elements
Element: quantity (value, expression, function, …)
Examples:

 x
 3.60  0.01 2.1  e x
x
  5.46 0.00 1.6  ,  2 x 2
, a1 a2 a3  ,  y 
   e x 
 z 

H&B A-5
Matrix
r  c matrix: r rows, c columns
mij : element at row i and column j.

 m11 m12  m1c 


m m  m 
M  21 22 2c 
   
 
 mr1 mr 2  mrc 
H&B A-5
Matrix
r  c matrix: r rows, c columns
mij : element at row i and column j.

 m11 m12  m1c 


m m  m 
M  21 22 2c 
   
 
 mr1 mr 2  mrc  r  c
elements
H&B A-5
Matrix
r  c matrix: r rows, c columns
mij : element at row i and column j.

 m11 m12  m1c 


m m  m 
M  21 22 2c 
   
 
 mr1 mr 2  mrc 
c columns H&B A-5
Matrix
r  c matrix: r rows, c columns
mij : element at row i and column j.

 m11 m12  m1c 


m  
 21 m22 m2 c  r rows
M
   
 
 mr1 mr 2  mrc 
H&B A-5
Matrix
Column vector: Row vector:
matrix with c =1 matrix with r =1
 v1  V v1 v2  vc 
v 
V 2
  Scalar:
  matrix with r=1and c=1
 vr 
V v 
Used for vectors
(and points)
H&B A-5
Matrix
Matrix as collection of column vectors:

 ux vx wx 
M U V W   u y vy w y 
 u z vz wz  W

Matrix contains an axis-frame:


V U

H&B A-5
Operations on matrices
• Multiplication with scalar
– simple
• Addition
– simple
• Matrix-matrix multiplication
– More difficult, but the most important

H&B A-5
Scalar Matrix multiplication
Matrix M multiplied with scalar s:
 sm11 sm12  sm1c 
 sm sm2c 
 21 sm22 
A sM  , i.e., aij smij
    
 
 smr1 smr 2  smrc 
 3 x 12  x 4
example :   3 
 6 2 y 2 y 
H&B A-5
Scalar Matrix addition
 a11 a12  a1c   b11 b12  b1c 
a   b b2c 
 21 a 22 a 2 c   21 b22 
M A  B  
       
   
a
 r1 a r2  a rc   br1 br 2  brc 
 a11  b11 a12  b12  a1c  b1c 
a b a  b  a  b 
 21 21 22 22 2c 2c 
, i.e., mij aij  bij
    
 
a 
 r 1 r1b a r2  b r2  a rc  brc 

 3 x 12   4  10  3 x  4 2 
example :     
 6 2 y  2 0   8 2 y 
H&B A-5
Scalar Matrix addition
 a11 a12  a1c   b11 b12  b1c 
a   b b2c 
 21 a 22 a 2 c   21 b22 
M A  B  
       
   
 ar1 ar 2  arc   br1 br 2  brc 
 a11  b11 a12  b12  a1c  b1c 
a b a  b  a  b 
 21 21 22 22 2c 2c 
, i.e., mij aij  bij
    
 
 ar1  br1 ar 2  br 2  arc  brc 

• Just add elements pairwise


• A and B must have the same number of rows and columns
• Generalization of vector and scalar addition H&B A-5
Matrix Matrix multiplication
 a11 a12  a1n   b11 b12  b1q 
a b 
a22  a2 n   21 b 22  b2q 
C AB  21
       
   
 amn am 2  amn   b p1 b p 2  b pq 
n
i = 2 ; k j = 1 ; k
cij a k 1
ik bkj

• cij: dot product of row vector ai and column vector bj


• #columns A must be the same as #rows B: n = p
• C: m  q matrix H&B A-5
Matrix Matrix multiplication
Example:

 2 3  2 1  3 3 2 2  3 4  11 16
  1  4  1 2   1 1  4 3  1 2  4 4   13  16
   3 4    
 0 5    0 1  5 3 0 2  5 4  15 20
i=3 j=2 i=3, j=2

H&B A-5
Matrix Matrix multiplication
Example:
 4
A 1 2 3 , B  5
 6

AB 

BA 

H&B A-5
Matrix Matrix multiplication
Example:
 4
A 1 2 3 , B  5
 6
 4
AB 1 2 3  5 1 4  2 5  3 6 32
 6

BA 

H&B A-5
Matrix Matrix multiplication
Example:
 4
A 1 2 3 , B  5 AB 
 6 BA
 4
AB 1 2 3  5 1 4  2 5  3 6 32
 6
 4  4 1 4 2 4 3  4 8 12
BA  5 1 2 3  5 1 5 2 5 3  5 10 15
 6  6 1 6 2 6 3  6 12 18
H&B A-5
Matrix Matrix multiplication
• AB  BA
Matrix matrix multiplication is not commutative!
Order matters!

• A(B+C) = AB+AC
Matrix matrix multiplication is distributive

H&B A-5
Example transformation sequence
(coordinate version)
X ' X : x'  px  qy, y ' rx  sy;
X ' '  X ': x' ' ax'by ' , y ' ' cx'dy '.

Then X ' '  X :

x' ' a ( px  qy )  b(rx  sy ), Unclear!


y ' ' c( px  qy )  d (rx  sy ); Error-prone!
or
x' ' (ap  br ) x  (aq  bs) y,
y ' ' (cp  dr ) x  (cq  ds) y.
H&B A-5
Example transformation sequence
(matrix vector version)
 x'  p q   x 
X '  X :       ;
 y '  r s   y 
 x' '  a b   x'
X ' '  X ':       .
 y ' '  c d   y '

Then X ' '  X :

 x' '  a b   p q   x   ap  br aq  bs   x
 y ' '  c d   r s   y   cp  dr cq  ds   y
          
H&B A-5
Example transformation sequence
(compact matrix vector version)
X '  X : X' AX ; Here some more detail :
X ' '  X ': X'' BX'  x  x'  x' '
X   , X' '   , X' '   ,
 y  y '  y ' '
Then X ' '  X :  p q  a b
A   ; B   .
 r s c d
X'' BAX

Matrix vector notation allows for compactness


and genericity!
H&B A-5
Matrix Transpose
 a11 a12  a1c 
a  Transpose matrix:
a  a
M  21 22 2c 
Interchange rows and columns.
   
  r  c matrix M  c  r matrix
a
 r1 a r2  a rc 
MT
 a11 a21  ar1 
a a22  ar 2 
M T  12 , i.e., mTji mij
   
 
 a1c a2c  arc 

 1 4
T  x
 1 2 3  2 5 ,
examples :     [x y z ]T  y 
 4 5 6  H&B A-5
 3 6  z 
Matrix Inverse
Simple algebra puzzle. Let ax = b. What is x?
ax b Multiply left and right with a  1
a  1ax a  1b Use a  1a equals 1
x a  1b Done

Linear algebra puzzle. Let MU = V. What is U?


MU V Multiply left and right with M  1
M  1MU M  1V Use M  1M equals I
U M  1V Done!

H&B A-5
Matrix Inverse
Inverse of a n n (square) matrix M is denoted M  1 , with
MM  1 M  1M I,
where I is the identity matrix :
1 0  0
0 0
1 1 if i  j
I  , i.e., I ij  .
   0 if i  j
 
0 0  1
I is a diagonal matrix, with all 1' s on the diagonal.
M  1 " undoes" the effect of M,
multiplying with I has no effect.
H&B A-5
Matrix Inverse examples
4 1 1 / 4
1
3 2  2  1
5   
 4   5 / 2 3 / 2 
3 2  2  1  3 2  2 5 / 2  3 1  2 3 / 2  1 0
5  
 4   5 / 2 3 / 2  5 2  4 5 / 2  5 1  4 3 / 2  0 1
   

H&B A-5
Matrix Inverse examples
1
 a b
c d ?
 
1
 a b 1  d  b
c d  
  ad  bc   c a 

 a b   d  b   ad  bc  ab  ba   1 0
c d  c    (ad  bc)  
  a    ab  ba  cb  ad   0 1 
1
 2 1
 4 2 ? Does not exist, cannot be inverted.
  H&B A-5
Matrix Inverse
- Does not always exist
- In general: if determinant = | M | = 0, matrix
cannot be inverted
- Inverse for n = 1 and n = 2: easy
- Inverse for higher n: use library function
- Important special case: orthonormal matrix.

H&B A-5
Overview
• Coordinates, points, vectors
– definitions, operations, examples
• Matrices
– definitions, operations, examples

You might also like