Title: 2IV60 Computer Graphics Basic Math for CG
12IV60 Computer GraphicsBasic Math for CG
2Overview
- Coordinates, points, vectors
- Matrices
HB A-1
3nD 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
HB A-2
4Coordinates
x
y
(x,y)
(x,y)
y
x
Standard Screen (output,
input)
HB A-1
5Polar coordinates
y
(x,y)
r
?
x
HB A-1
63D coordinates 1
(x,y,z)
z
(x,y,z)
z
x
y
x
y
Right-handed Left-handed
HB A-1
73D coordinates 2
(x,y,z)
(x,y,z)
z (middle)
z (middle)
y (index)
x (thumb)
x (thumb)
y (index)
Right-handed Left-handed
HB A-1
83D coordinates 3
(x,y,z)
z
y
x
?
HB A-1
93D coordinates 4
(x,y,z)
z
f
r
y
x
?
HB A-1
10Points
- Point position in nD space
- Notation P (HB), also P, p, p en p
- (x,y,z) (HB), also (x1, x2, x3), (Px, Py, Pz),
- (r, ?, z), ( r, ?, ?),
HB A-2
11Vectors 1
- Vector
- arrow
- multiple interpretations (displacement, velocity,
force, ) - has a magnitude and direction
- has no position
- Notation V (HB), also V, v, v en v
- (Vx, Vy, Vz) (HB), also (x, y, z), (x1, x2, x3)
HB A-2
12Vectors 2
y
P2
y2
P1
y1
V directed line segment, or difference between
two points
x
x1
x2
HB A-2
13Vectors 3
HB A-2
14Vectors 4
- Direction of a vector Direction angles.
- Unit vector V
- Magnitude info is removed, direction is kept.
z
g
b
y
x
a
HB A-2
15Vector addition
- Add components, put vector head to tail
y
y
W
VW
W
V
V
x
x
HB A-2
16Scalar multiplication of vector
- Multiplication components with scalar s
y
y
2V
V
x
x
HB A-2
17Combining vector operations
- Infinite line through P with direction V
- L(t) P Vt, t ??
V
y
P
t
x
t parameter along line t ?a, b line segment
HB A-2
18Vector multiplication 1
- Scalar product or dot product
- Product of parallel components, gives 1 real
value
W
V
q
W cos q
V
HB A-2
19Vector multiplication 2
HB A-2
20Vector multiplication 3
- Vector product or cross product gives a vector
(in 3D) - n perpendicular to V and W
V?W
W
q
V
n
HB A-2
21Vector multiplication 5
HB A-2
22Vector multiplication 6
- Scalar product
- scalar
- Test if vectors are perpendicular
- cos
- project,
- Vector product
- vector
- Get a vector perpendicular to two given vectors
- sin
- surface area,
HB A-2
23Exercise 1
- Given a point P.
- Requested Reflect a point Q with respect to P.
Q
W P Q Q Q 2W 2P Q or P (P
Q )
P
Q
We dont need coordinates!
24Exercise 1
- Given a point P.
- Requested Reflect a point Q with respect to P.
Q
Alternative P is halfway Q and Q P (Q
Q)/2 2P Q Q Q 2P Q
P
Q
25Exercise 2
- Given a line L L(t) P Vt .
- Requested Reflect a point Q with respect to L.
We know Q Q 2 W W L(t) Q W. V 0
L(t)
V
y
P
t
x
26Exercise 2
We know L(t) P Vt Q Q 2 W W L(t)
Q W. V 0
Substitute to get t (L(t) Q).V 0 (P Vt
Q).V 0 V .V t (P Q).V 0 t ((Q P).V) /
(V .V)
Then Q Q 2 (P Vt Q) 2P Q
V((Q P).V / V .V)
27Steps 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?
28Exercise 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 a . What is the new position R of
R?
P
Q
R
29Circle in space
y
C(?)
r
?
x
A1, B1, 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
-
30Exercise 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
Q
R
31Use
- Scalar product, cross product
- coordinate independent definitions
- vector algebra
- Dont use
- arccos, arcsin
- y f(x)
32Very short intro to Linear Algebra
- System of linear equations
- Such systems occur in many, many applications.
- They are studied in Linear Algebra.
HB A-5
33Very 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?
HB A-5
34Very short intro to Linear Algebra
- System of linear equations
- Crucial in computer graphics
- Transforming geometric objects
- Change of coordinates
HB A-5
35Example transformation
y
P (x,y)
x
y
P
V
U
y
x
x
HB A-5
36What is a matrix?
- Matrix
- Mathematical objects with operations
- Matrix in computer graphics
- Defines a coordinate frame
- Defines a transformation
- Handy tool for manipulating transformations
HB A-5
37Matrix
- Matrix rectangular array of elements
- Element quantity (value, expression, function,
) - Examples
HB A-5
38Matrix
- r ? c matrix r rows, c columns
- mij element at row i and column j.
HB A-5
39Matrix
- r ? c matrix r rows, c columns
- mij element at row i and column j.
r ? c elements
HB A-5
40Matrix
- r ? c matrix r rows, c columns
- mij element at row i and column j.
HB A-5
41Matrix
- r ? c matrix r rows, c columns
- mij element at row i and column j.
HB A-5
42Matrix
Column vector matrix with c 1 Used for
vectors (and points)
HB A-5
43Matrix
- Matrix as collection of column vectors
HB A-5
44Operations on matrices
- Multiplication with scalar
- simple
- Addition
- simple
- Matrix-matrix multiplication
- More difficult, but the most important
HB A-5
45Scalar Matrix multiplication
- Matrix M multiplied with scalar s
HB A-5
46Scalar Matrix addition
HB A-5
47Scalar Matrix addition
- Just add elements pairwise
- A and B must have the same number of rows and
columns - Generalization of vector and scalar addition
HB A-5
48Matrix Matrix multiplication
j 1 k?
- 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
HB A-5
49Matrix Matrix multiplication
Example
i 3
j 2
i3, j2
HB A-5
50Matrix Matrix multiplication
Example
HB A-5
51Matrix Matrix multiplication
Example
HB A-5
52Matrix Matrix multiplication
Example
HB A-5
53Matrix Matrix multiplication
- AB ? BA
- Matrix matrix multiplication is not commutative!
- Order matters!
- A(BC) ABAC
- Matrix matrix multiplication is distributive
HB A-5
54Example transformation sequence (coordinate
version)
Unclear! Error-prone!
HB A-5
55Example transformation sequence (matrix vector
version)
HB A-5
56Example transformation sequence (compact matrix
vector version)
Matrix vector notation allows for compactness
and genericity!
HB A-5
57Matrix Transpose
Transpose matrix Interchange rows and columns. r
? c matrix M ? c ? r matrix MT
HB A-5
58Matrix Inverse
Simple algebra puzzle. Let ax b. What is x?
Linear algebra puzzle. Let MU V. What is U?
HB A-5
59Matrix Inverse
HB A-5
60Matrix Inverse examples
HB A-5
61Matrix Inverse examples
Does not exist, cannot be inverted.
HB A-5
62Matrix 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.
HB A-5
63Overview
- Coordinates, points, vectors
- definitions, operations, examples
- Matrices
- definitions, operations, examples