CS 428: Fall 2010 Introduction to ... - Rutgers University
Transcript of CS 428: Fall 2010 Introduction to ... - Rutgers University
CS 428: Fall 2010
Introduction to
Computer GraphicsComputer Graphics
Geometric Transformations
9/15/2010 1Andrew Nealen, Rutgers, 2010
Topic overview
� Image formation and OpenGL (last week)
� Modeling the image formation process
� OpenGL primitives, OpenGL state machine
� Transformations and viewing� Transformations and viewing
� Polygons and polygon meshes
� Programmable pipelines
� Modeling and animation
� Rendering
Andrew Nealen, Rutgers, 2010 9/15/2010 2
Topic overview
� Image formation and OpenGL
� Transformations and viewing (next weeks)
� Linear algebra review, Homogeneous coordinates
� Geometric + projective transformations� Geometric + projective transformations
� Viewing, Viewports, Clipping
� Polygons and polygon meshes
� Programmable pipelines
� Modeling and animation
� RenderingAndrew Nealen, Rutgers, 2010 9/15/2010 3
Transformations in CG
� Specify placement of objects in the world
� relative to the configuration in which they are
defined
� Allow for reuse of objects � Allow for reuse of objects
in different places, sizes
� Specify the camera
position
� Specify the camera model
(projection)
Andrew Nealen, Rutgers, 2010 9/15/2010 4
Transformations in CG
� The “where” is specified by translations and
rotations (= rigid body motions)
� Shape changes include
� For now we will only use linear deformations
� Linear algebra!Andrew Nealen, Rutgers, 2010 9/15/2010 5
Representations in CG
� Computations should not depend on
coordinate system (such as midpoint/origin)
� Need careful accounting of points and vectors
� Both (3 tuples of floating point values)3ℜ∈� Both (3 tuples of floating point values)
� Vectors
� Displacements, velocities, directions, trajectories,
surface normals, etc.
� Points
� Locations!
Andrew Nealen, Rutgers, 2010 9/15/2010 6
3ℜ∈
Vector/point operations
� Vector + vector = vector
� Point + vector = point
� Point + point = invalid!
� Street address analogy
� Point – point = vector
� Works!Andrew Nealen, Rutgers, 2010 9/15/2010 7
Vector review
� [p + q]i = pi + qi addition
� [s p]i = s ∙ pi scalar multiplication
� || p || = sqrt[ (pi)2 ] length
Andrew Nealen, Rutgers, 2010 9/15/2010 8
Vector review
� p ∙ q = Σ pi ∙ qi dot product
� Normalization
Andrew Nealen, Rutgers, 2010 9/15/2010 9
θ
p
q
p
pp =ˆ
θcos⋅⋅ qp
Perpendicular vectors
, 0
( , ) ( , )v v v vx y y x⊥
< >=
= ⇒ = ± −
v w
v v
v
v⊥In 2D only!
9/15/2010 10Andrew Nealen, Rutgers, 2010
Linear combination + Basis
� Linear combination
� λ1 ∙ v1 + λ2 ∙ v2 + … + λn ∙ vn with λi∈ R
� Linear independence of vectors v1, …, vn
� λ ∙ v + … + λ ∙ v = 0 only when λ = … = λ = 0� λ1 ∙ v1 + … + λn ∙ vn = 0 only when λi = … = λ n = 0
� Basis of n-dimensions is a set of n linearly
independent vectors
� Every vector in Rn has a unique set of λ’s to
represent it → Cartesian coordinates
Andrew Nealen, Rutgers, 2010 9/15/2010 11
Inner (dot) product
� Defined for vectors:
, || || || || cosθ< >= ⋅ ⋅v w v w
L
θ
L v
wL
cosθ || ||
,
|| ||L
=
< >=
w
v w
v
Projection of w onto v
9/15/2010 12Andrew Nealen, Rutgers, 2010
v
q
q’
2 2 2
:
(1) dist( , ) || ||L ′+ = −0
Pythagoras
q q q p
l
Distance between point and line
p0
q’
2 2 2
22
2
,(2)
|| ||
dist( , ) || ||
,|| || .
|| ||
L
L
< − >=
′⇒ = − − =
< − >= − −
0
0
00
q p v
v
q q q p
q p vq p
v
L
9/15/2010 13Andrew Nealen, Rutgers, 2010
Representation of a plane
in 3D space
� A plane π is defined by a normal n and one
point in the plane p0.
� A point q ∈ plane ⇔ < q – p0 , n > = 0
� The normal n is perpendicular to all vectors in � The normal n is perpendicular to all vectors in
the plane
Andrew Nealen, Rutgers, 2010 9/15/2010 14
n
p0
q
π
Distance between point and plane
� Geometric way:
� Project (q - p0) onto n!
0| , |dist
< − >=
q p n
Andrew Nealen, Rutgers, 2010 9/15/2010 15
n
p0
q
π
dist =n
Coordinates
� Connect drawing plane/space with R2 or R3
� Coordinate origin and axes are problem
specific
� Example: orthogonal coordinates in the lower � Example: orthogonal coordinates in the lower
corner of this room
� Affine spaces have
� No fixed origin
� No fixed axes
� (which is not the case in linear spaces)
9/15/2010 16Andrew Nealen, Rutgers, 2010
CoordinatesAffine space
� “An affine space is a vector space that's
forgotten its origin” – John Baez
� In R3, the origin, lines and planes through the
origin and the whole space are linear origin and the whole space are linear
� points, lines and planes in general as well as the
whole space are the affine subspaces.
Linear subspace Affine subspace9/15/2010 17Andrew Nealen, Rutgers, 2010
PrimitivesPoints
9/15/2010 18Andrew Nealen, Rutgers, 2010
PrimitivesLines
9/15/2010 19Andrew Nealen, Rutgers, 2010
PrimitivesTriangles
9/15/2010 20Andrew Nealen, Rutgers, 2010
PrimitivesShapes
9/15/2010 21Andrew Nealen, Rutgers, 2010
PrimitivesShapes … are tessellated
9/15/2010 22Andrew Nealen, Rutgers, 2010
PrimitivesPositioning
� Absolute coordinates?
Andrew Nealen, Rutgers, 2010 9/15/2010 23
PrimitivesPositioning
� Transformation +
relative coordinates
� Translation
� Rotation
� Scaling
� Shearing
� Affine maps /
Transformations!
Andrew Nealen, Rutgers, 2010 9/15/2010 24
Affine mapsAffine combinations
� The set
is an affine combination of vectors v (or of
=⋅=∈ ∑ ∑= =
n
i
n
i
iii mitvvVv0 0
1,| λλ
is an affine combination of vectors vi (or of
points pi).
v0
v1
vp0
p
p1
9/15/2010 25Andrew Nealen, Rutgers, 2010
Affine maps Barycentric coordinates
� Given and affine space A with coordinate
system B={p0,…pn}
� For a point with
the λ are known as barycentric coordinates
∑=
⋅=n
i
i pp0
1λ ∑=
=n
i
i
0
1λ
the λi are known as barycentric coordinates
� Physical interpretation:
� Points pi have mass λi → p ist the centroid (= center of
mass)
p0
p
p1110 =+ λλ
01
0
1
01
1
0
pp
pp
pp
pp
−
−=
−
−=
λ
λ
9/15/2010 26Andrew Nealen, Rutgers, 2010
p0 p1
p2
p
( )( )( )( )( )( )( )( )210
201
210
210
,,
,,
,,
,,
pppA
pppA
pppA
pppA
∆∆
=
∆∆
=
λ
λ
Affine maps Barycentric coordinates
( )( )( )( )( )( )210
102
210
,,
,,
,,
pppA
pppA
pppA
∆∆
=
∆
λ221100 pppp ⋅+⋅+⋅= λλλ
( )( ) ( ) ( )02012102
1,, pppppppA −×−=∆
9/15/2010 27Andrew Nealen, Rutgers, 2010
Affine mapsConvex hull
� The set
is the convex hull co{p0,...,pn} of points p0,...,pn
{ }
=≥=⋅== ∑ ∑= =
n
i
n
i
iiiin niundpppppco0 0
0 ,...,0,0,1,|,..., λλλ
� The convex hull contains all convex
combinations of the points
� Convex combinations =
affine combinations /w
barycentric coordinates
greater/equal to zero p0
p1
p2
p3
p4
p5
9/15/2010 28Andrew Nealen, Rutgers, 2010
Affine maps…as linear maps
� A map Φ: Rn→ Rm is affine
� when Φ can be represented as Φ(v)=A(v)+b
where A is a linear map and b ∈ Rm
� Affine maps have a linear part (multiplication) � Affine maps have a linear part (multiplication)
and a translation (additive)
Linear
transformation Translation
+
=
0
0
0
222120
121110
020100
'
'
'
z
y
x
z
y
x
aaa
aaa
aaa
z
y
x
9/15/2010 29Andrew Nealen, Rutgers, 2010
Affine transformations
� Preserve parallel lines
� lines → lines, planes → planes
� Might not preserve length and angles
� But do preserve relative length along lines� But do preserve relative length along lines
� If they do preserve length and angles then the
transformation is an isometry
� Affine = linear + translation
Andrew Nealen, Rutgers, 2010 9/15/2010 30
Affine maps…as linear maps
� Leads to the use of projective geometry
� 2D points and vectors represented as
(x, y, w) → homogeneous coordinates
w = 1 pointw = 1 point
w = 0 vector
� Point (0, 0, 0) not allowed, so domain
R3 – {(0, 0, 0)}
� If w ∈ (0,1] then (x, y, w) → (x/w, y/w, 1)
A point
9/15/2010 31Andrew Nealen, Rutgers, 2010
What is w ?2D case!
� A kind of a type
� Points + “points at
infinity”
� Points at infinity are not� Points at infinity are not
affected by translation
� Infinite # of points
correspond to (x, y, 1)
→ {(tx, ty, t) | t ≠ 0}
� Line through origin
– {origin}Andrew Nealen, Rutgers, 2010 9/15/2010 32
Homogeneous coordinates
� Works nicely for points and vectors
� Adding and scaling works too
� More in “projections”, where w ∈ [0,1]
Andrew Nealen, Rutgers, 2010 9/15/2010 33
Linear transformation
� Purely linear transformation
� Origin does not move
� New coordinate axes are lin. comb. of old ones
Andrew Nealen, Rutgers, 2010 9/15/2010 34
Linear transformation
� Purely linear transformation
Andrew Nealen, Rutgers, 2010 9/15/2010 35
Affine transformationas a linear transformation + translation in n dimensions
� Origin moves → translation
Andrew Nealen, Rutgers, 2010 9/15/2010 36
Affine transformationas a linear transformation in n+1 dimensions
� Origin moves → translation
Andrew Nealen, Rutgers, 2010 9/15/2010 37
What is so great about this?
� Easy to implement
� Checks for errors in the implementation
� Can always check the w coordinate to make sure
that points and vectors remain unchangedthat points and vectors remain unchanged
� Unified representation for linear + translation
� Can compose many transformations into a single
matrix through concatenation
Andrew Nealen, Rutgers, 2010 9/15/2010 38
M = Mrot ∙ Mscale ∙ Mtranslate ∙ …