HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.
-
Upload
annis-summers -
Category
Documents
-
view
221 -
download
3
Transcript of HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.
HCT
Geometric Transforms
RotationTranslationShearScaleThese are the operations done by HCT
Homogeneous
What does homogeneous mean?-the same
Coordinate Transform
What is a coordinate transform?P=(1,2)Translate P by P1=(2,3)?P’ = P+P1 = (3,5).So translation is an example of a coordinate transform.
Scale, in 2D
P=(1,1)Scale P by Sc=(2,3).P’ = P * Sc = (2,3)
P2=(1,4), now scale by Sc.P2’=(2,12).
Summary
Translation is addition.Scaling is multiplication.Both are coordinate transformations
Rotation
By Euler we get:Z=real Part + imaginary partZ = r + im*IBy polar coordinates we write an angle and a magnitude:Z = r exp(I * theta)
cos siniz re r ri
iz re
Euler
cos siniz re r ri
Rotation
1
2
1 2 1 2
1
2
( )1 2* *
i
i
i i i
z re
z e
z z re e re
Summary
Addition = translationMultiply by real numbers = scalingMultiply by complex number = rotationThese are different operations. They are not HCTs.HCTs concatenate all above operations into a single operation.
Learning Objectives
Learn how 2D transformations are represented in 3D. Recognize the inverse matrix for a homogeneous transformation. Understand how the transformations also represent coordinate frame transformations. Understand the concept of a matrix stack.
2D Translation and 3D Translation
]1,,,[ zyxX
1
0100
0010
0001
zyx ttt
T
]1,,,[ zyx tztytxTX
]1,,[ yxX
1
010
001
yx tt
T
]1,,[ yx tytxTX
2D Rotation
]1,,[ yxX
100
0cossin
0sincos
T
]1,cossin,sincos[ yxyxTX
Laws of Exponents1
2
1 2 1 2
1
2
( )1 2* *
i
i
i i i
z re
z e
z z re e re
cos siniz re r ri
Use the trig identities
sin(A+B)=sin A cos B + cos A sin Bcos(A+B)=cos A cos B - sin A sin Bhint, write sin(theta1+theta2)
3D Rotation – Z Axis
]1,,,[ zyxX
1000
0100
00cossin
00sincos
T
]1,,cossin,sincos[ zyxyxTX
About the Z axis
x
y
z
3D Rotation – X Axis
]1,,,[ zyxX
1000
0cossin0
0sincos0
0001
T
]1,cossin,sincos,[ zyzyxTX
About the Z axis
x
y
z
3D Rotation – Y Axis
]1,,,[ zyxX
1000
0cos0sin
0010
0sin0cos
T
]1,cossin,,sincos[ zxyzxTX
About the Z axis
x
y
z
Inverse Matrices
The 3x3 rotation submatrix is orthogonal. The inverse of the 3x3 matrix is the transform of the original matrix The inverse of the translation component is just the reverse translation.
Composition of Transforms
Various motions can be tacked, one after the other, in a long sequence of matrices: T1T2T3…T4
These combinations will maintain the relative shape of the vectors processed, but will shift them around the original coordinate frame.
Thinking of Reference Frames
Another way to think of this mathematics, is to imagine transforming the coordinate frame to a new place
y0
z0
x1
y1
z1
T(5,0,2)
Transformation, T, moves things 5 to the right and 2 up. The whole coordinate frame moves to a new position
x0
Coordinate Rotation
y0
z0
x1
y1R(y=-35)
z1
x0
The Matrix Stack
While drawing a world, you often want to draw with respect to a convenient coordinate frame The graphics card need only keep track of the current position (current transformation) If you want to shift to the left, multiply the current frame by a left translation When done, shift back to the right
Learning Objectives
Learn how 2D transformations are represented in 3D. Recognize the inverse matrix for a homogeneous transformation. Understand how the transformations also represent coordinate frame transformations. Understand the concept of a matrix stack.
Rendering: Transformations
So far, discussion has been in screen spaceBut model is stored in model space(a.k.a. object space or world space)Three sets of geometric transformations: Modeling transforms Viewing transforms Projection transforms
Rendering: Transformations
Modeling transforms Size, place, scale, and rotate objects
parts of the model w.r.t. each other Object coordinates world
coordinates
Z
X
Y
X
Z
Y
Rendering: Transformations
All these transformations involve shifting coordinate systems (i.e., basis sets)That’s what matrices do…Represent coordinates as vectors, transforms as matrices
Multiply matrices = concatenate transforms!
y
x
y
x
cossin
sincos
'
'
Rendering: Transformations
Homogeneous coordinates: represent coordinates in 3 dimensions with a 4-vector Denoted [x, y, z, w]
Note that typically w = 1 in model coordinates To get 3-D coordinates, divide by w:
[x’, y’, z’] = [x/w, y/w, z/w]
Transformations are 4x4 matricesWhy? To handle translation, rotation and projection uniformly
TranslationsFor convenience we usually describe objects in relation to their own coordinate system Solar system example
We can translate or move points to a new position by adding offsets to their coordinates:
Note that this translates all points uniformly
z
y
x
t
t
t
z
y
x
z
y
x
'
'
'
2-D Rotation
(x, y)
(x’, y’)
x’ = x cos() - y sin()y’ = x sin() + y cos()
(Draw it)
2-D Rotations
Rotations in 2-D are easy:
3-D is more complicated Need to specify an axis of rotation Common pedagogy: express rotation about this
axis as the composition of canonical rotations Canonical rotations: rotation about X-axis, Y-axis, Z-
axis
y
x
y
x
cossin
sincos
'
'
3-D RotationsBasic idea: Using rotations about X, Y, Z axes, rotate
model until desired axis of rotation coincides with Z-axis
Perform rotation in the X-Y plane (i.e., about Z-axis)
Reverse the initial rotations to get back into the initial frame of reference
Objections: Difficult & error prone Ambiguous: several combinations about the
canonical axis give the same result
ScalingScaling a coordinate means multiplying each of its components by a scalarUniform scaling means this scalar is the same for all components:
2
ScalingNon-uniform scaling: different scalars per component:
How can we represent this in matrix form?
X 2,Y 0.5
Scaling
Scaling operation:
Or, in matrix form:
cz
by
ax
z
y
x
'
'
'
z
y
x
c
b
a
z
y
x
00
00
00
'
'
'
scaling matrix
2-D Rotation
This is easy to capture in matrix form:
3-D is more complicated Need to specify an axis of rotation Simple cases: rotation about X, Y, Z axes
y
x
y
x
cossin
sincos
'
'
3-D RotationWhat does the 3-D rotation matrix look like for a rotation about the Z-axis? Build it coordinate-by-coordinate
z
y
x
z
y
x
100
0)cos()sin(
0)sin()cos(
'
'
'
3-D Rotation
What does the 3-D rotation matrix look like for a rotation about the Y-axis? Build it coordinate-by-coordinate
z
y
x
z
y
x
)cos(0)sin(
010
)sin(0)cos(
'
'
'
3-D Rotation
What does the 3-D rotation matrix look like for a rotation about the X-axis? Build it coordinate-by-coordinate
z
y
x
z
y
x
)cos()sin(0
)sin()cos(0
001
'
'
'
Translation Matrices?
We can composite scale matrices just as we did rotation matricesBut how to represent translation as a matrix?Answer: with homogeneous coordinates
Homogeneous Coordinates
Homogeneous coordinates: represent coordinates in 3 dimensions with a 4-vector
(Note that typically w = 1 in object coordinates)
w
z
y
x
wz
wy
wx
zyx
1
/
/
/
),,(
Homogeneous Coordinates
Homogeneous coordinates seem unintuitive, but they make graphics operations much easierOur transformation matrices are now 4x4:
1000
0)cos()sin(0
0)sin()cos(0
0001
xR
Homogeneous Coordinates
Homogeneous coordinates seem unintuitive, but they make graphics operations much easierOur transformation matrices are now 4x4:
1000
0)cos(0)sin(
0010
0)sin(0)cos(
yR
Homogeneous Coordinates
Homogeneous coordinates seem unintuitive, but they make graphics operations much easierOur transformation matrices are now 4x4:
1000
0100
00)cos()sin(
00)sin()cos(
zR
Homogeneous Coordinates
Homogeneous coordinates seem unintuitive, but they make graphics operations much easierOur transformation matrices are now 4x4:
1000
000
000
000
z
y
x
S
S
S
S
Homogeneous Coordinates
How can we represent translation as a 4x4 matrix?A: Using the rightmost column:
1000
000
000
000
z
y
x
T
T
T
T
2D Vs. 3D
2 Dimensional (2D) objects have just a height and a width, for example a drawing of a rectangle on a sheet of paper.
This can be described in terms of X & Y coordinates.
3 Dimensional (3D) objects have a height, width and depth, for example a cardboard box.
These can be described in terms of X, Y & Z.
Vectors
In computer graphics and mathematics, a Vector is just a term for Direction and Length.
A vector can also describe a Displacement.
A displacement is just a distance travelled in a certain direction.
A vector (x,y,z) may be visualised as a line with one end tied to the origin and the other at (x,y,z) with an arrow at this point.
Vectors 2
A 3D vector has 3 degrees of freedom.
3 separate numbers are required to describe a 3D vector.
Vectors 3
Normal VectorsA Normal Vector is simply a vector that points at right angles to something else. Normally a surface in computer graphics.
Vector OperationsAddition
The sum of two (or more) vectors is simply the sum of their displacements
Vectors are summed by individually summing the X, Y & Z components
Consider the following vector addition (-2,1,0) + (0,0,1) + (-1,-1,0) + (0,0,-1) = (-3,0,0)
Simply adding the individual components of each, as you would add any number, provides the new vector (-3,0,0)
Vector OperationsScaling
Vector Scaling changes a vectors length by a Scale Factor.
For example if the vector (2,0,0) is scaled by a factor of 3, it becomes (6,0,0)
If the scale factor is a positive number, the vectors direction remains unchanged
If the scale factor is a negative number, the vectors direction is flipped (180 degrees)
Vector OperationsNote that the Vector labelled ? cannot be obtained by scaling the original vector, since its direction is not parallel
Vector Operations Norm of a vector
The norm of a vector gives its length (providing a metric for 3D space)
The norm of a vector (x,y,z) gives us the distance from the origin to the point (x,y,z).
Normalising a vector gives us a vector that has the same direction and length 1
Vector OperationsSimilarity of DirectionIt is often useful to know how much two vectors are pointing in the same directionFor example we may wish to know how much a surface is pointing toward a light source (when calculating illumination)This means we need to find the variation in direction between the vector from the surface to the light source, and the surface normal vectorThis will produce a number between 1 and –1 1 indicates that the vectors are directionally identical 0 indicates that the vectors are at right-angles -1 indicates that the vectors are pointing in exactly the
opposite direction
Vector OperationsDot Product
Similarity of direction is more commonly referred to as the Vector Dot Product.
The dot product of two normalised vectors is simply the length of the projection of one vector onto the other.
This is illustrated in the following slide.
Vector OperationsDot Product
The dot product of two unit vectors is 1 when they point in the same direction, 0 when they are at right angles and -1 when they point in opposite directions
Vector OperationsCross Product
Cross product is an operation to find a vector that is perpendicular to two existing vectors
You may need to do this to find the surface normal vector when you have two vectors pointing in different directions along the surface
In computer graphics, it is generally the direction of the resulting cross product that is of interest
In the example on the following slide, the yellow vector is the normalised cross product of the red and green vectors
Vector OperationsCross Product
3D Transforms
Once an object has been modelled, it is frequently desirable to move, rotate or distort it.
These modifications can be completed by the use of a 3D transform
3D transforms relate to the coordinate space
Coordinate Spaces
Before points may be plotted within a 3D ( or 2D) space, the coordinate space must be defined
Within a coordinate space there is one point where a axis cross, this is termed the origin
For each axis starting at the origin, a vector is specified that will move +1 along that axis
For a 3D space there are 3 vectors (one for each axis) representing X, Y & Z
A vector that defines +1 along a given axis is termed a Basis Vector
Coordinate Spaces 2
The Red arrow represents the X axis, Green the Y axis and Blue the Z axis
Coordinate Spaces 3This coordinate space definition is Relative not Absolute
It is a way to define a new coordinate space relative to an existing one
The origin and basis vectors need to be defined in a space. The origin of the new space is coordinates of a point in the old space
It can be thought of as a vector from the original spaces origin to the new spaces origin
Since this is the displacement of the new space from the old, this vector may be termed the Displacement Vector
Coordinate Space
Merging Transforms
The 3rd space is defined in terms of the 2nd, which in turn in defined in terms of the 1st
This is the same 3rd space as defined in the previous slide, this time derived directly from the 1st
Merging Transforms
Other Transforms
Transforms can be used for many operations including translation, rotation, displacement and skewing
The following slides show several transform operations applied to the figure below
Other Transforms
Displacing the objects coordinate system to (0.6,0.5,0) from the original position
Other Transforms
Displacing and Scaling. All 3 basis vectors are scaled by 1/2
Other Transforms
Displacement and Non-uniform scaling. The Y basis is scaled by 2, while the Z basis is scaled by 1/2
Other Transforms
Displacement and Rotation. The coordinate space is rotated 300 about the Z axis, and 100 degrees about the X