Title: Simple Mathematics for graphics
1Simple Mathematics for graphics
2Volumes from Silhouettes
- Start with collection of calibrated images
3Volumes from Silhouettes
43D Curves from Edges
- Feature-based stereo matching
53D Curves from Edges
- Extract extremal and internal edges
63D Curves from Edges
- Match curves along epipolar lines
7What is Computer Graphics?
- Using a computer to generate an image from a
representation.
computer
Model
Image
8Representations
- How do we represent an object?
- Points
- p x y z
- Mathematical Functions
- X2 Y2R2
- Polygons (most commonly used)
- Points
- Connectivity
9Representing Points and Vectors
- A 3D point p x y z
- Represents a location with respect to some
coordinate system - A 3D vector v x y z
- Represents a displacement from a position
10Linear Algebra
- Why study Linear Algebra?
- Deals with the representation and operations
commonly used in Computer Graphics
11Vector Spaces
- Consists of a set of elements, called vectors and
two operations that are defined on them, addition
and multiplication
12Vector Addition
- Given V X Y Z and W A B C
- VW XA YB ZC
- Properties of Vector addition
- Commutative VWWV
- Associative (UV)W U(VW)
- Additive Identity V0 V
- Additive Inverse VW 0, W-V
13Parallelogram Rule
- To visualize what a vector addition is doing,
here is a 2D example
VW
V
W
14Vector Multiplication
- Given V X Y Z and a Scalar s and t
- sV sX sY sZ
- Properties of Vector multiplication
- Associative (st)V s(tV)
- Multiplicative Identity 1V V
- Scalar Distribution (st)V sVtV
- Vector Distribution s(VW) sVsW
15Dot Product and Distances
- Given u x y z and v a b c
- vu axbycz
- The Euclidean distance of u from the origin is
sqrt( x2y2z2) and is denoted by u - Notice that u sqrt(uu)
- The Euclidean distance between u and v is sqrt(
(x-a) 2(y-b) 2(z-c) 2) ) and is denoted by
u-v
16Properties of the Dot Product
- Given a vector u, v, w and scalar s
- The result of a dot product is a SCALAR value
- Commutative vw wv
- Non-degenerate vv0 only when v0
- Bilinear v(usw)vus(vw)
17Angles and Projection
- Alternative view of the dot product
- vwv w cos(?) where ? is the angle
between v and w - If v is a unit vector (v 1) then if we
perpendicularly project w onto v can call this
newly projected vector u then u vw
w
v
u
18Matrices
- A compact way of representing operations on
points and vectors - 3x3 Matrix A looks like
- a(i,j) refers to the element of matrix A
19Matrix Multiplication
- If A is an n?k matrix and B is a k?p then AB is a
n?p matrix with entries c(i,j)where - c(i,j)?a(i,s)b(s,j)
- Alternatively, if we took the rows of A and
columns of B as individual vectors then - c(i,j)AiBj where the subscript refers to the
row and column, respectively
20Matrix Multiplication Properties
- Associative (AB)C A(BC)
- Distributive A(BC) ABAC
- Multiplicative Identity I diag(1) (square
matrix - NOT commutative AB?BA
21Determinant of a Matrix
- Defined on a square matrix (nxn)
- Where A1i determinant of (n-1)x(n-1) submatrix A
gotten by deleting the first row and the ith
column
22Recursive Definition!!
- The basis case
- det of a 2x2 matrix is defined to be ad-bc where
23Uses of the Determinant?
- Linear Independence of columns in a matrix
- Cross Product
- Given 2 vectors vv1 v2 v3, ww1 w2 w3, the
cross product is defined to be the determinant of
24Cross Product Properties
- The Cross Product of v and w is denoted by v?w
- Is a VECTOR, perpendicular to the plane defined
by v and w - v?wv w sin?
- ? is the angle between v and w
- v?w-(w?v)
v?w
w
v
25Matrix Transpose and Inverse
- The Transpose of a matrix A, denoted by AT is
defined as aijaji (exchanging the rows and
columns) - If A and B are nxn matrices and ABBAI then B is
the inverse of A, denoted by A-1 - (AB)-1B-1A-1 same applies for transpose
26Methods for finding the Inverse
- Explicit Methods
- Gaussian-Jordan Elimination
- Create the Augmented matrix AI and reduce the
left side to the identity using elementary row
operations and the right hand side will be the
inverse. ie. IA-1 - Cramers Rule
- Solve for A where aijdet(submatrix(Aij))
- A-1(1/det(A))(A)T
27Implicit Methods
- Instead of explicitly calculating A-1, there are
techniques that solve equations of the form Axb
(system of linear equations). - Clearly xA-1b but we do not need to explicitly
calculate A-1 to calculate x. - LU Decomposition
- QR Factorization
- Singular Value Decomposition (SVD)
- Conjugate Gradient if sparse
28Transformations
- Why use transformations?
- Create object in convenient coordinates
- Reuse basic shape multiple times
- Hierarchical modeling
- System independent
- Virtual cameras
29Translation
30Properties of Translation
31Rotations (2D)
32Rotations 2D
33Rotations (3D)
34Properties of Rotations
order matters!
35Combining Translation Rotation
36Combining Translation Rotation
37Scaling
Uniform scaling iff
38Homogeneous Coordinates
can be represented as
where
39Translation Revisited
40Rotation Scaling Revisited
41Combining Transformations
where
42Transforming Tangents
43Transforming Normals
44Rotations about an arbitrary axis
Rotate by around a unit axis
45- We can view the rotation around an arbitrary axis
as a set of simpler steps - We know how to rotate and translate around the
world coordinate system - Can we use this knowledge to perform the rotation?
46Rotation about an arbitrary axis
- Translate the space so that the origin of the
unit vector is on the world origin - Rotate such that the extremity of the vector now
lies in the xz plane (x-axis rotation) - Rotate such that the point lies in the z-axis
(y-axis rotation) - Perform the rotation around the z-axis
- Undo the previous transformations
47Rotation about an arbitrary axis
y
(a,b,c)
x
x
z
48Closer Look at Y-Z Plane
- Need to rotate ? degrees around the x-axis
y
?
z
49Equations for ?
50Rotation about the Y-axis
- Using the same analysis as before, we need to
rotate ? degrees around the Y-axis
y
x
z
51Rotation about the Z-axis
- Now, it is aligned with the Z-axis, thus we can
simply rotate ? degrees around the Z-axis. - Then undo all the transformations we just did
52Equation summary
53Deformations
- Transformations that do not preserve shape
- Non-uniform scaling
- Shearing
- Tapering
- Twisting
- Bending
54Shearing
55Tapering
Image courtesy of Watt, 3D Computer Graphics
56Twisting
Image courtesy of Watt, 3D Computer Graphics
57Bending
Image courtesy of Watt, 3D Computer Graphics
58What have we seen so far?
- Basic representations (point, vector)
- Basic operations on points and vectors (dot
product, cross products, etc.) - Transformation manipulative operators on the
basic representation (translate, rotate,
deformations) 4x4 matrices to encode all
these.
59Why do we need this?
- In order to generate a picture from a model, we
need to be able to not only specify a model
(representation) but also manipulate the model in
order to create more interesting images.
60Overview
- The next set of slides will deal with the other
half of the process (at least in a simplistic
fashion) - From a model, how do we generate an image
computer
Model
Image
61Accumulation of Transformations
Example Robot arm
62Orthonormal Coordinates
Iff u and v are orthonormal
63Coordinate Systems
- Object coordinates
- World coordinates
- Camera coordinates
- Normalized device coordinates
- Window coordinates
64Object Coordinates
- Convenient place to model the object
65World Coordinates
- Common coordinates for the scene
66Camera Coordinates
- Coordinate system with the camera in a convenient
pose
67Normalized Device Coordinates
- Device independent coordinates
- Visible coordinate usually range from
68Window Coordinates
- Adjusting the NDC to fit the window
is the lower left of the window
height
width
69Perspective Projection
- Taking the camera coordinates to NDC
70Perspective Projection
71Rasterization
3
2
1
0
0
1
2
3
4
72Rasterizing Lines
Given two endpoints, find the pixels that make
up the line.
73Rasterizing Lines
- Requirements
- No gaps
- Minimize error (distance to line)
74Rasterizing Lines
Assume 1 lt m lt 1, x0 lt x1
Line(int x0, int y0, int x1, int y1) float dx
x1 x0 float dy y1 y0 float m
dy/dx float x x0, y y0 for(x x0 x lt
x1 x) setPixel(x,round(y)) y ym
75Rasterizing Lines
- Problems with previous algorithm
- round takes time
- uses floating point arithmetic
76Midpoint Algorithm
NE
Q
M
E
P(x,y)
If Q lt M, choose E. If Q gt M, choose NE
77Implicit Form of a Line
Implicit form
Explicit form
Positive below the line Negative above the
line Zero on the line
78Decision Function
Choose NE if d gt 0 Choose E if d lt 0
79Incrementing d
If choosing E
But
So
80Incrementing d
If choosing NE
But
So
81Initializing d
Multiply everything by 2 to remove fractions
(doesnt change the sign)
82Midpoint Algorithm
Assume 0 lt m lt 1, x0 lt x1
Line(int x0, int y0, int x1, int y1) int dx
x1 x0, dy y1 y0 int d 2dy-dx int
delE 2dy, delNE 2(dy-dx) int x x0, y
y0 setPixel(x,y) while(x lt x1)
if(dlt0) d delE x x1 else
d delNE x x1 y y1
setPixel(x,y)
See Bresenham Algorithm
83Limitations?
- The midpoint line algorithm assumes that the
slope (m) is between 0 and 1 - This implies that this algorithm only applies to
lines in region 1 - Extending to other regions left as an a
programming assignment
2
3
1
4
5
8
7
6
84Anti-aliasing Lines
Lines appear jaggy
Sampling is inadequate
85Anti-aliasing Lines
Trade intensity resolution for spatial resolution
86Anti-aliasing Lines
Assume 0 lt m lt 1, x0 lt x1
Line(int x0, int y0, int x1, int y1) float dx
x1 x0 float dy y1 y0 float m
dy/dx float x x0, y y0 for(x x0 x lt
x1 x) int yi floor(y) float f y
yi setPixel(x,yi, 1-f)
setPixel(x,yi1, f) y ym
87Putting it all together!!
- Take your representation (points) and transform
it from Object Space to World Space - Take your World Space point and transform it to
Camera Space - Perform the remapping and projection onto the
image plane in Normalized Device Coordinates - Perform this set of transformations on each point
of the polygonal object - Connect the dots through line rasterization
88Intuitively
World Space
Object Space
Camera Space
Rasterization