Graphics 02 Transformations PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

Image Processing and Computer Graphics

Transformations and
Homogeneous Coordinates
Matthias Teschner

Computer Science Department


University of Freiburg
Motivation
 transformations are used
 to position, reshape, and animate
objects, lights, and the virtual camera
 to orthographically or perspectivly project
three-dimensional geometry onto a plane
 transformations are represented with 4x4 matrices
 transformations are applied to vertices and normals
 vertices (positions) and normals (directions) are
represented with 4D vectors

University of Freiburg – Computer Science Department – Computer Graphics - 2


Outline
 transformations in the rendering pipeline
 motivations for the homogeneous notation
 homogeneous notation
 basic transformations in homogeneous notation
 compositing transformations
 summary

University of Freiburg – Computer Science Department – Computer Graphics - 3


Vertex Processing
 modelview transform
 (lighting)
 projection transform
 (clipping)
 viewport transform

University of Freiburg – Computer Science Department – Computer Graphics - 4


Modelview Transform

Inverse
M1
M3 M2
V-1

V M4
[Akenine-Moeller et al.: Real-time Rendering]

 M1, M2, M3, M4, V are matrices representing transformations


 M1, M2, M3, M4 are model transforms to place the objects in the scene
 V places and orientates the camera in space
 V-1 transforms the camera to the origin looking along the negative z-axis
 model and view transforms are combined in the modelview transform
 the modelview transform V-1M1..4 is applied to the objects
University of Freiburg – Computer Science Department – Computer Graphics - 5
Projection Transform
 P transforms the view volume to the canonical view volume
 the view volume depends on the camera properties
 orthographic projection  cuboid
 perspective projection  pyramidal frustum

Porthographic Pperspective
[Song Ho Ahn]
 canonical view volume is a cube from (-1,-1,-1) to (1,1,1)
 view volume is specified by near, far, left, right, bottom, top
University of Freiburg – Computer Science Department – Computer Graphics - 6
Viewport Transform /
Screen Mapping
 projected primitive coordinates (xp, yp, zp) are
transformed to screen coordinates (xs, ys)
 screen coordinates together with depth value are
window coordinates (xs, ys, zw)

[Akenine-Moeller et al.: Real-time Rendering]


University of Freiburg – Computer Science Department – Computer Graphics - 7
Vertex Transforms
object space

 modelview transform
eye space / camera space

 projection transform
normalized
device coordinates
 viewport transform
window space

University of Freiburg – Computer Science Department – Computer Graphics - 8


Vertex Transforms
local object space
 model transform
world coordinate space
 inverse view transform
eye space / camera space
 projection transform
normalized
device coordinates
 viewport transform
window space
University of Freiburg – Computer Science Department – Computer Graphics - 9
Outline
 transformations in the rendering pipeline
 motivations for the homogeneous notation
 homogeneous notation
 basic transformations in homogeneous notation
 compositing transformations
 summary

University of Freiburg – Computer Science Department – Computer Graphics - 10


Some Transformations
 congruent transformations
(Euclidean transformations)
 preserve shape and size
 translation, rotation, reflection
 similarity transformations
 preserve shape
 translation, rotation, reflection, scale

University of Freiburg – Computer Science Department – Computer Graphics - 11


Affine Transformations
 preserve collinearity
 points on a line are transformed to points on a line
 preserve proportions
 ratios of distances between points are preserved
 preserve parallelism
 parallel lines are transformed to parallel lines
 angles and lengths are not preserved
 translation, rotation, reflection, scale, shear are affine
 orthographic projection is a combination of affine transf.
 perspective projection is not affine

University of Freiburg – Computer Science Department – Computer Graphics - 12


Affine Transformations
 affine transformations of a 3D point p:
 affine transformations preserve affine combinations
for
 e.g., a line can be transformed
by transforming its control points

University of Freiburg – Computer Science Department – Computer Graphics - 13


Affine Transformations
 affine transformations of a 3D point p

 the 3x3 matrix A represents scale and rotation


 the 3D vector t represents translation
 using homogeneous coordinates,
all affine transformations are represented
with one matrix-vector multiplication

University of Freiburg – Computer Science Department – Computer Graphics - 14


Points and Vectors
 the rendering pipeline transforms vertices,
normals, colors, texture coordinates
 points (e.g. vertices) specify a location in space
 vectors (e.g. normals) specify a direction
 relations between points and vectors
 point - point = vector
 point + vector = point
 vector + vector = vector
 point + point = not defined

University of Freiburg – Computer Science Department – Computer Graphics - 15


Points and Vectors
 transformations can have different
effects on points and vectors
 translation
 translation of a point moves the point to a different position
 translation of a vector does not change the vector
 using homogeneous coordinates,
transformations of vectors and points
can be handled in a unified way

University of Freiburg – Computer Science Department – Computer Graphics - 16


Outline
 transformations in the rendering pipeline
 motivations for the homogeneous notation
 homogeneous notation
 basic transformations in homogeneous notation
 compositing transformations
 summary

University of Freiburg – Computer Science Department – Computer Graphics - 17


Homogeneous Coordinates of Points
 with w ≠ 0 are the homogeneous
coordinates of the 3D point
 represents the same point
for all  with  ≠ 0
 examples
 (2, 3, 4, 1)  (2, 3, 4)
 (2, 4, 6, 1)  (2, 4, 6)
 (4, 8, 12, 2)  (2, 4, 6)

University of Freiburg – Computer Science Department – Computer Graphics - 18


1D Illustration

University of Freiburg – Computer Science Department – Computer Graphics - 19


Homogeneous Coordinates of Vectors
 for varying w , a point is scaled and the
points represent a line in 3D space
 the direction of this line is characterized by
 for w  0, the point moves to infinity
in the direction
 is a point at infinity in the direction of
 is a vector in the direction of

University of Freiburg – Computer Science Department – Computer Graphics - 20


1D Illustration

University of Freiburg – Computer Science Department – Computer Graphics - 21


Points and Vectors
 if points are represented in the homogeneous (norma-
lized) form, point - vector relations can be represented
 vector + vector = vector

 point + vector = point

 point - point = vector

University of Freiburg – Computer Science Department – Computer Graphics - 22


Homogeneous Representation
of Linear Transformations

 if the transform of results in , then

 the transform of results in

University of Freiburg – Computer Science Department – Computer Graphics - 23


Affine Transformations and Projections

 general form

 mii represent rotation, scale


 ti represent translation
 pi represent projection
 w is analog to the fourth component
for points / vectors
University of Freiburg – Computer Science Department – Computer Graphics - 24
Homogeneous Coordinates - Summary

 with w ≠ 0 are the homogeneous


coordinates of the 3D point
 is a point at infinity in the direction of
 is a vector in the direction of
 is a transformation,
representing rotation, scale,
translation, projection

University of Freiburg – Computer Science Department – Computer Graphics - 25


Outline
 transformations in the rendering pipeline
 motivations for the homogeneous notation
 homogeneous notation
 basic transformations in homogeneous notation
 compositing transformations
 summary

University of Freiburg – Computer Science Department – Computer Graphics - 26


Translation
 of a point

 of a vector

 inverse (T-1 "undoes" the transform T)

University of Freiburg – Computer Science Department – Computer Graphics - 27


Rotation
 positive (anticlockwise)
rotation with angle 
around the x-, y-, z-axis

University of Freiburg – Computer Science Department – Computer Graphics - 28


Inverse Rotation

 the inverse of a rotation matrix


corresponds to its transpose
University of Freiburg – Computer Science Department – Computer Graphics - 29
Mirroring / Reflection
 mirroring with respect to x =0, y =0, z =0 plane
 changes the sign of the x -, y -, z - component

 the inverse of a reflection


corresponds to its transpose

University of Freiburg – Computer Science Department – Computer Graphics - 30


Orthogonal Matrices
 rotation and reflection matrices are orthogonal

 are orthogonal  is orthogonal


 rotation: reflection:
 length of a vector does not change
 angles are preserved

University of Freiburg – Computer Science Department – Computer Graphics - 31


Scale
 scaling x -, y - , z - components of a point or vector

 inverse
 uniform scaling: sx = sy = sz = s

University of Freiburg – Computer Science Department – Computer Graphics - 32


Shear
 one component is offset
with respect to another component
 six basic shear modes in 3D
 e.g., shear of x with respect to z

 inverse

University of Freiburg – Computer Science Department – Computer Graphics - 33


Basis Transform - Translation
 two coordinate systems

University of Freiburg – Computer Science Department – Computer Graphics - 34


Basis Transform - Translation
 the coordinates of with respect to are given
by
 the coordinates of a point in the transformed
basis correspond to the coordinates of point in the
untransformed basis transformed by the inverse
basis transform
 translating the origin by t corresponds
to translating the object by -t
 also: rotating the basis vectors by an angle corresponds
to rotating the object by the same negative angle

University of Freiburg – Computer Science Department – Computer Graphics - 35


Basis Transform - Rotation
 two coordinate systems

University of Freiburg – Computer Science Department – Computer Graphics - 36


Basis Transform - Rotation
 the coordinates of with respect to are given by

 b1, b2, b3 are the basis vectors of C2 with respect to C1


 b1, b2, b3 are orthonormal, therefore
the basis transform is a rotation
 rotating the basis vectors by an angle corresponds
to rotating the object by the same negative angle
University of Freiburg – Computer Science Department – Computer Graphics - 37
Basis Transform - Application
 the view transform can be seen as a basis transform
 objects are placed with respect to
a (global) coordinate system
 the camera is also positioned at and oriented at
given by viewing direction and up-vector
 after the view transform, all objects are represented in
the eye or camera coordinate system
 placing and orienting the camera corresponds to the
application of the inverse transform to the objects
 rotating the camera by R and translating it by T,
corresponds to translating the objects by T-1 and
rotating them by R -1
University of Freiburg – Computer Science Department – Computer Graphics - 38
Planes and Normals
 planes can be represented by a surface normal n and
a point r. All points p with form a plane.

 the transformed points


are on the plane represented by

 if a surface is transformed by A, its homogeneous notation


(including the surface normal) is transformed by (A-1)T
University of Freiburg – Computer Science Department – Computer Graphics - 39
Outline
 transformations in the rendering pipeline
 motivations for the homogeneous notation
 homogeneous notation
 basic transformations in homogeneous notation
 compositing transformations
 summary

University of Freiburg – Computer Science Department – Computer Graphics - 40


Compositing Transformations
 composition is achieved by matrix multiplication
 a translation T applied to p, followed by a rotation R

 a rotation R applied to p, followed by a translation T

 note that generally


 the order of composed transformations matters

University of Freiburg – Computer Science Department – Computer Graphics - 41


Examples
 rotation around a line through t parallel
to the x-, y-, z- axis

 scale with respect to an arbitrary axis

 e.g., b1, b2, b3 represent an orthonormal basis,


then scaling along these vectors can be done by

University of Freiburg – Computer Science Department – Computer Graphics - 42


Rigid-Body Transform

with R being a rotation and t being a


translation is a combined transformation
 inverse

 in Euclidean coordinates
 the inverse transform
 therefore

University of Freiburg – Computer Science Department – Computer Graphics - 43


Outline
 transformations in the rendering pipeline
 motivations for the homogeneous notation
 homogeneous notation
 basic transformations in homogeneous notation
 compositing transformations
 summary

University of Freiburg – Computer Science Department – Computer Graphics - 44


Summary
 usage of the homogeneous notation is motivated
by a unified processing of affine transformations,
perspective projections, points, and vectors
 all transformations of points and vectors are
represented by a matrix-vector multiplication
 "undoing" a transformation is represented by
its inverse
 compositing of transformations is accomplished
by matrix multiplication

University of Freiburg – Computer Science Department – Computer Graphics - 45

You might also like