HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

72
HCT

Transcript of HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Page 1: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

HCT

Page 2: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Geometric Transforms

RotationTranslationShearScaleThese are the operations done by HCT

Page 3: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Homogeneous

What does homogeneous mean?-the same

Page 4: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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.

Page 5: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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).

Page 6: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Summary

Translation is addition.Scaling is multiplication.Both are coordinate transformations

Page 7: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 8: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Euler

cos siniz re r ri

Page 9: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 10: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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.

Page 11: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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.

Page 12: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 13: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

2D Rotation

]1,,[ yxX

100

0cossin

0sincos

T

]1,cossin,sincos[ yxyxTX

Page 14: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 15: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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)

Page 16: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

3D Rotation – Z Axis

]1,,,[ zyxX

1000

0100

00cossin

00sincos

T

]1,,cossin,sincos[ zyxyxTX

About the Z axis

x

y

z

Page 17: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

3D Rotation – X Axis

]1,,,[ zyxX

1000

0cossin0

0sincos0

0001

T

]1,cossin,sincos,[ zyzyxTX

About the Z axis

x

y

z

Page 18: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

3D Rotation – Y Axis

]1,,,[ zyxX

1000

0cos0sin

0010

0sin0cos

T

]1,cossin,,sincos[ zxyzxTX

About the Z axis

x

y

z

Page 19: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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.

Page 20: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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.

Page 21: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 22: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Coordinate Rotation

y0

z0

x1

y1R(y=-35)

z1

x0

Page 23: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 24: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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.

Page 25: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 26: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 27: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

'

'

Page 28: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 29: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

'

'

'

Page 30: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

2-D Rotation

(x, y)

(x’, y’)

x’ = x cos() - y sin()y’ = x sin() + y cos()

(Draw it)

Page 31: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

'

'

Page 32: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 33: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

ScalingScaling a coordinate means multiplying each of its components by a scalarUniform scaling means this scalar is the same for all components:

2

Page 34: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

ScalingNon-uniform scaling: different scalars per component:

How can we represent this in matrix form?

X 2,Y 0.5

Page 35: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 36: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

'

'

Page 37: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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(

'

'

'

Page 38: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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(

'

'

'

Page 39: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

'

'

'

Page 40: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Translation Matrices?

We can composite scale matrices just as we did rotation matricesBut how to represent translation as a matrix?Answer: with homogeneous coordinates

Page 41: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

/

/

/

),,(

Page 42: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 43: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 44: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 45: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 46: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 47: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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.

Page 48: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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.

Page 49: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Vectors 2

A 3D vector has 3 degrees of freedom.

3 separate numbers are required to describe a 3D vector.

Page 50: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Vectors 3

Page 51: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Normal VectorsA Normal Vector is simply a vector that points at right angles to something else. Normally a surface in computer graphics.

Page 52: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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)

Page 53: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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)

Page 54: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Vector OperationsNote that the Vector labelled ? cannot be obtained by scaling the original vector, since its direction is not parallel

Page 55: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 56: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 57: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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.

Page 58: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 59: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 60: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Vector OperationsCross Product

Page 61: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 62: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 63: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Coordinate Spaces 2

The Red arrow represents the X axis, Green the Y axis and Blue the Z axis

Page 64: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 65: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Coordinate Space

Page 66: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Merging Transforms

The 3rd space is defined in terms of the 2nd, which in turn in defined in terms of the 1st

Page 67: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

This is the same 3rd space as defined in the previous slide, this time derived directly from the 1st

Merging Transforms

Page 68: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

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

Page 69: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Other Transforms

Displacing the objects coordinate system to (0.6,0.5,0) from the original position

Page 70: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Other Transforms

Displacing and Scaling. All 3 basis vectors are scaled by 1/2

Page 71: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Other Transforms

Displacement and Non-uniform scaling. The Y basis is scaled by 2, while the Z basis is scaled by 1/2

Page 72: HCT. Geometric Transforms Rotation Translation Shear Scale These are the operations done by HCT.

Other Transforms

Displacement and Rotation. The coordinate space is rotated 300 about the Z axis, and 100 degrees about the X