2D and 3D Transformations, Homogeneous Coordinates Lecture 03 Patrick Karlsson [email protected]Centre for Image Analysis Uppsala University Computer Graphics November 6 2006 Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 1 / 23 Reading Instructions Chapters 4.1–4.9. Edward Angel. “Interactive Computer Graphics: A Top-down Approach with OpenGL”, Fourth Edition, Addison-Wesley, 2004. Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 2 / 23
12
Embed
2D and 3D Transformations, Homogeneous Coordinates ... · PDF file2D and 3D Transformations, Homogeneous Coordinates Lecture 03 Patrick Karlsson @cb.uu.se Centre for Image Analysis
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 1 / 23
Reading InstructionsChapters 4.1–4.9.
Edward Angel.“Interactive Computer Graphics: A Top-downApproach with OpenGL”,Fourth Edition, Addison-Wesley, 2004.
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 2 / 23
Todays lecture ...in the pipeline
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 3 / 23
Scalars, points, and vectors
Scalars α, β
Real (or complex) numbers.
Points P, QLocations in space (but no size or shape).
Vectors u, vDirections in space (magnitude but no position).
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 4 / 23
Mathematical spaces
Scalar fieldA set of scalars obeying certain properties. New scalars can be formedthrough addition and multiplication.
(Linear) Vector spaceMade up of scalars and vectors. New vectors can be created throughscalar-vector multiplication, and vector-vector addition.
Affine spaceAn extended vector space that include points. This gives us additionaloperators, such as vector-point addition, and point-point subtraction.
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 5 / 23
Data types
Polygon based objectsObjects are described using polygons.
A polygon is defined by its vertices (i.e., points).
Transformations manipulate the vertices, thus manipulates theobjects.
Some examples in 2DScalar α 1 float.
Point P(x , y) 2 floats.
Vector v(x , y) 2 floats.
Matrix M 4 floats.
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 6 / 23
Transformations
To create and move objects we need to be able to transformobjects in different ways.
There are many classes of transformations.
TransformationsTranslate (Move around.)
Rotate
Scale
Shear (Scaling and rotation.)
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 7 / 23
TransformationsTranslation
Simply add a translation vector
x ′ = x + dx
y ′ = y + dy
P(x,y)
P’(x’,y’)
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 8 / 23
TransformationsRotation
P(x , y) in polar coordinates
x = r cos(φ) y = r sin(φ)
P ′(x ′, y ′) in polar coordinates
x ′ = r cos(θ + φ) = r cos(φ) cos(θ) − r sin(φ) sin(θ)
y ′ = r sin(θ + φ) = r cos(φ) sin(θ) − r sin(φ) cos(θ)
Substitute x and y
x ′ = x cos(θ) − y sin(θ)
y ′ = x sin(θ) + y cos(θ)
θφ
r
r
P(x,y)
P’(x’,y’)
x
y
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 9 / 23
TransformationsRotation
Arbitrary rotationTranslate the rotation axis to the origin.
Rotate.
Translate back.
y
x
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 10 / 23
TransformationsScaling around the origin
Multiply by a scale factor
x ′ = sxx
y ′ = syy
x
y
P(x,y)
P’(x’,y’)
x x’
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 11 / 23
TransformationsShear
Shear in the x direction
x ′ = x + y cot(θ)
y ′ = y
x
y
θ
P(x,y) P’(x’,y’)
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 12 / 23
Affine transforms are linear!
αf (x1 + x2) = αf (x1) + αf (x2)
The linearity implies that in order to move an object we only needto transform the individual vertices making up the object, since theinner points are defined by linear combinations of the vertices.
P0
P1
P(α) = (1− α)P0 + αP1 α = [0, 1]
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 13 / 23
Vector mathshort revision
The inner (or dot) product is written as u · v . If u · v = 0, thenvectors u and v are orthogonal.
The squared magnitude of a vector v is given by the inner productv · v = ||v ||2.
The angle between two vectors u and v is given byu·v
||u||||v || = cos(θ).
Two nonparallel vectors can generate a third vector that isorthogonal to them both by using the cross product n = u × v .The new vector n can be then be used to create a vector that isorthogonal to both u and n by performing w = u × n. The threevectors u, n, and w are mutually orthogonal.
The magnitude of a cross product gives the sine of the anglebetween the vectors, | sin(θ)| = ||u×v ||
||u||||v || .
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 14 / 23
Vectors and matrices
Translation „x ′
y ′
«=
„xy
«+
„dxdy
«
Rotation „x ′
y ′
«=
„cos(θ) − sin(θ)sin(θ) cos(θ)
« „xy
«
Scaling „x ′
y ′
«=
„sx 00 sy
« „xy
«
Shearx „x ′
y ′
«=
„1 cot(θ)0 1
« „xy
«
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 15 / 23
Translation is different!
Translation in 2D „x ′
y ′
«=
„xy
«+
„dxdy
«
“Stepping up one dimension”0@ x ′
y ′
W
1A =
0@ 1 0 dx0 1 dy0 0 1
1A 0@ xyW
1A
If W = 1, then this called a Homogeneous coordinate0@ x ′
y ′
1
1A =
0@ 1 0 dx0 1 dy0 0 1
1A 0@ xy1
1A
Patrick Karlsson (Uppsala University) Transformations and Homogeneous Coords. Computer Graphics 16 / 23