Simple Mathematics for graphics - PowerPoint PPT Presentation

1 / 88
About This Presentation
Title:

Simple Mathematics for graphics

Description:

... for graphics. Volumes from Silhouettes. Start with collection of 'calibrated' images. Volumes from Silhouettes. Cup on turntable example. 3D Curves from Edges ' ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 89
Provided by: CHUA3
Category:

less

Transcript and Presenter's Notes

Title: Simple Mathematics for graphics


1
Simple Mathematics for graphics
2
Volumes from Silhouettes
  • Start with collection of calibrated images

3
Volumes from Silhouettes
  • Cup on turntable example

4
3D Curves from Edges
  • Feature-based stereo matching

5
3D Curves from Edges
  • Extract extremal and internal edges

6
3D Curves from Edges
  • Match curves along epipolar lines

7
What is Computer Graphics?
  • Using a computer to generate an image from a
    representation.

computer
Model
Image
8
Representations
  • How do we represent an object?
  • Points
  • p x y z
  • Mathematical Functions
  • X2 Y2R2
  • Polygons (most commonly used)
  • Points
  • Connectivity

9
Representing 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

10
Linear Algebra
  • Why study Linear Algebra?
  • Deals with the representation and operations
    commonly used in Computer Graphics

11
Vector Spaces
  • Consists of a set of elements, called vectors and
    two operations that are defined on them, addition
    and multiplication

12
Vector 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

13
Parallelogram Rule
  • To visualize what a vector addition is doing,
    here is a 2D example

VW
V
W
14
Vector 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

15
Dot 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

16
Properties 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)

17
Angles 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
18
Matrices
  • 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

19
Matrix 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

20
Matrix Multiplication Properties
  • Associative (AB)C A(BC)
  • Distributive A(BC) ABAC
  • Multiplicative Identity I diag(1) (square
    matrix
  • NOT commutative AB?BA

21
Determinant 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

22
Recursive Definition!!
  • The basis case
  • det of a 2x2 matrix is defined to be ad-bc where

23
Uses 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

24
Cross 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
25
Matrix 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

26
Methods 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

27
Implicit 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

28
Transformations
  • Why use transformations?
  • Create object in convenient coordinates
  • Reuse basic shape multiple times
  • Hierarchical modeling
  • System independent
  • Virtual cameras

29
Translation




30
Properties of Translation




31
Rotations (2D)
32
Rotations 2D
  • So in matrix notation

33
Rotations (3D)
34
Properties of Rotations
order matters!
35
Combining Translation Rotation
36
Combining Translation Rotation
37
Scaling
Uniform scaling iff
38
Homogeneous Coordinates
can be represented as
where
39
Translation Revisited
40
Rotation Scaling Revisited
41
Combining Transformations
where
42
Transforming Tangents
43
Transforming Normals
44
Rotations 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?

46
Rotation 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

47
Rotation about an arbitrary axis
  • Step 1
  • Rotate x-axis

y
(a,b,c)
x
x
z
48
Closer Look at Y-Z Plane
  • Need to rotate ? degrees around the x-axis

y
?
z
49
Equations for ?
50
Rotation about the Y-axis
  • Using the same analysis as before, we need to
    rotate ? degrees around the Y-axis

y
x
z
51
Rotation 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

52
Equation summary
53
Deformations
  • Transformations that do not preserve shape
  • Non-uniform scaling
  • Shearing
  • Tapering
  • Twisting
  • Bending

54
Shearing
55
Tapering
Image courtesy of Watt, 3D Computer Graphics
56
Twisting
Image courtesy of Watt, 3D Computer Graphics
57
Bending
Image courtesy of Watt, 3D Computer Graphics
58
What 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.

59
Why 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.

60
Overview
  • 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
61
Accumulation of Transformations
Example Robot arm
62
Orthonormal Coordinates
Iff u and v are orthonormal
63
Coordinate Systems
  • Object coordinates
  • World coordinates
  • Camera coordinates
  • Normalized device coordinates
  • Window coordinates

64
Object Coordinates
  • Convenient place to model the object

65
World Coordinates
  • Common coordinates for the scene

66
Camera Coordinates
  • Coordinate system with the camera in a convenient
    pose

67
Normalized Device Coordinates
  • Device independent coordinates
  • Visible coordinate usually range from

68
Window Coordinates
  • Adjusting the NDC to fit the window

is the lower left of the window
height
width
69
Perspective Projection
  • Taking the camera coordinates to NDC

70
Perspective Projection
71
Rasterization
  • Array of pixels

3
2
1
0
0
1
2
3
4
72
Rasterizing Lines
Given two endpoints, find the pixels that make
up the line.
73
Rasterizing Lines
  • Requirements
  • No gaps
  • Minimize error (distance to line)

74
Rasterizing 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
75
Rasterizing Lines
  • Problems with previous algorithm
  • round takes time
  • uses floating point arithmetic

76
Midpoint Algorithm
NE
Q
M
E
P(x,y)
If Q lt M, choose E. If Q gt M, choose NE
77
Implicit Form of a Line
Implicit form
Explicit form
Positive below the line Negative above the
line Zero on the line
78
Decision Function
Choose NE if d gt 0 Choose E if d lt 0
79
Incrementing d
If choosing E
But
So
80
Incrementing d
If choosing NE
But
So
81
Initializing d
Multiply everything by 2 to remove fractions
(doesnt change the sign)
82
Midpoint 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
83
Limitations?
  • 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
84
Anti-aliasing Lines
Lines appear jaggy
Sampling is inadequate
85
Anti-aliasing Lines
Trade intensity resolution for spatial resolution
86
Anti-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
87
Putting 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

88
Intuitively
World Space
Object Space
Camera Space
Rasterization
Write a Comment
User Comments (0)
About PowerShow.com