Class 01 Transformations

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

Transformations/Motion

To transform something is to change it. In geometry, there are specific


ways to describe how a figure is changed. The transformations we will
learn about include: * In Mathematics it is called
GEOMETRIC TRANSFORMATION (0, 0, 0).
•Translation
* In Computer Graphics it is called
•Rotation MOTION.
Motion
•Reflection
•Scaling
Renaming Transformations

It is common practice It is common practice to name


to name shape transformed shapes using the
using capital letters: same letters with a“prime”
*** A, B, C, D are Vertex.
symbol:
3D Transformations +y -Z

• Translation has 3 degrees of freedom


-X
• Rotation has 3 degrees of freedom +x

*** All the Transformations (Translation, Rotation, Reflection, Scaling) are 3D. +z
-y
*** Extra column is required to perform Addition
by Multiplication.

tx

ty

*** Rotation Matrix is a composite matrix of 3-different rotations. P' = P + T P' = P + T


*** Rotating across X-axis (X-value is constant), rotating on YZ-plane. x' = x + tx
*** Rotating across Y-axis (Y-value is constant), rotating on XZ-plane. y' = y + ty
*** Rotating across Z-axis (Z-value is constant), rotating on XY-plane. z' = z + tz
Homogeneous Coordinate System
• In computer graphics and geometry, the homogeneous coordinate
system is a mathematical tool used to represent points, vectors, and
transformations in a way that simplifies certain operations. It extends
the Cartesian coordinate system, which uses three numbers (x, y, z)
to represent points in three-dimensional space, to a four-dimensional
space by adding a fourth coordinate, w.
• A point (x, y, z) in 3D space can be represented in homogeneous
coordinates as (xw, yw, zw, w), where w is a scaling/weighting factor
that allows for translation and perspective projection. By adding this
fourth coordinate, transformations such as translation, rotation and
scaling can be represented as matrix multiplications, which simplifies
their implementation in computer graphics.
4
Translations
A Translation “slides” an object a fixed distance in a given
direction. The original object and its translation have the,
same shape and size and they face in the same direction
Translations in 2D

Let's examine some


translations related to
coordinate geometry.
The example shows how
each vertex moves the
same distance in the same
direction.
Write the Points
• What are the coordinates for A, B, C?
A(-4, 5), B(-1, 1) and C(-4,-1)
• What are the coordinates for A', B'. C'?
A' (2, 5), B'(5,1) and C'(2, -1)
• How are they alike?
They are similar triangles
x' 1 0 6 x
• How are they different?
y' = 0 1 0 y
Each vertex slides 6 units to the right 1 0 0 1 1
Write the points • What are the coordinates for A, B, C, D?
A (2, 4) B (4, 4) C (5, 2) D (2, 1)

• What are the coordinates for A', B', C', D'?


A'(-5, 1) B'(-3, 1) C'(-2, -1) D'(-5, -2)

• How did the transformation change the


points?
The figure slides 7 units to
the left and 3 units down
x' 1 0 -7 x
y' = 0 1 -3 y
1 0 0 1 1
3D Rotations

• Rotation has 3 degrees of freedom


Rotation
A rotation is a transformation that turns a figure about a fixed point
called the center of rotation. An object and its rotation are the same
shape and size, but the figures may be turned in different directions.
3D rotation consists of
3 simple rotation:
1. Rotation across z-axis
2. Rotation across y-axis
3. Rotation across x-axis
Rotation across z-axis Derivation of Rotation Matrix

In the figure a point P(x, y, z) makes an angle θ with x-axis:


x = rcosθ … (1)
y = rsinθ
P is further rotated by an angle β about the origin to P(x′, y′, z′). It can be written as:
x′ = rcos(θ + β) … (2)
y′ = rsin(θ + β)
P′(x′ y′, z′)
z′ = z
x′ = r(cosθ cosβ – sinθ sinβ)
= rcosθ cosβ – rsinθ sinβ
x' = x cosβ – y sinβ P(x y, z)
y′ = r(sinθ cosβ + cosθ sinβ)
= rsinθ cos(β) + rcosθ sinβ
= y cosβ + x sinβ
Y' = x sinβ + y cosβ
Z
Rotation across z-axis (+)ve rotation:
x′ = x cosβ – y sinβ Center of rotation (0, 0, 0)
y′ = x sinβ + y cosβ
z’ = z
x′ cosβ –sinβ 0 0 x
y′ = sinβ cosβ 0 0 y
z′ 0 0 1 0 z
1 0 0 0 1 1

For example, to rotate a 2D point by 900 the matrix becomes:

x′ 0 –1 0 x
y′ = 1 0 0 y
1 0 0 1 1
12
Thus the point (1, 0, 0) becomes (0, 1, 0).
Rotation in –ve angle
In the Figure the point P(x, y, z) is to be rotated by an angle - about the origin
to P(x′, y′, z′). It can be seen that:
x′ = r cos(θ – )
y′ = r sin(θ – ) P(x,y,z)

x′ = r(cosθ cos + sinθ sin) P’(x’,y’,z’)


= rcosθ cos + rsinθ sin

X' = x cos + y sin
θ
y′ = r(sinθ cos – cosθ sin)
= r(y/r cos – x/R sin) Z
Y'= – x sin + y cos
13
Rotation(-)ve rotation:
x′ = x cos  + y sin 
y′ = – x sin  + y cos 

x′ cos sin 0 x
y′ = –sin cos 0 y
1 0 0 1 1

For example, to rotate a point by -900 the matrix becomes:


x′ 0 1 0 x
y′ = -1 0 0 y
1 0 0 1 1
Thus the point (1, 0) becomes (0, -1). 14
Coordinate Transformation (Rotation in 3D)
To rotate a point (x, y, z) about an arbitrary center of rotation (px, py, pz)
(Center of rotation is not Origin)
x′ x

y′ = [translate(px, py, pz)] [rotate β] [translate(–px, –py,-pz)] y

z′ z

1 1

(-t matrix)
x′ 1 0 0 px cos –sin 0 0 1 0 0 -px x

y′ = 0 1 0 py sin cos 0 0 0 1 0 -py y

z′ 0 0 1 pz 0 0 1 1 0 0 1 -pz z

1 0 0 0 1 0 0 0 1 0 0 0 1 1

15
Coordinate Transformation (Rotation in 3D)
In computer graphics multiplication of 3matrix is used as one matrix.
in matrix form: Center of rotation in not-origin.

x′ cos  –sin  0 px(1–cos ) + py sin  x


y′ = sin  cos  0 py(1–cos ) – px sin  y
z′ 0 0 1 0 z
1 0 0 0 1 1

16
Coordinate Transformation (Rotation in 3D), alternate solution
To rotate a point (x, y, z) about an arbitrary center of rotation (px, py, pz)
1. Subtract (px, py, pz) from the coordinates (x, y, z) respectively. This enables us to perform
the rotation about the origin. Question:
x1 = (x – px) A 3D point is rotating across z-axis.
and center of rotation is (Px, Py, Pz),
y1 = (y – py) then derive 4-4 Matrix.
z1 = (z – pz)
2. Rotate  about the origin:
x2 = (x –px) cos  – (y –py) sin 
y2 = (x –px) sin  + (y –py) cos 
z2 = (z – pz)
3. Add (px, py, pz) to compensate for the original subtraction
x′= (x – px) cos  – (y – py) sin  + px
y′= (x – px) sin  + (y – py) cos  + py
z′= (z – pz) + pz 17
Rotation in 3D x′= x cos  –y sin  + px(1 –cos ) + py sin 
y′= x sin  + y cos  + py(1 –cos ) –px sin 
z′= z
in matrix form:
x′ cos  –sin  0 px(1–cos ) + py sin  x
y′ = sin  cos  0 py(1–cos ) – px sin  y
z′ 0 0 1 0 z
1 0 0 0 1 1
rotating a point 90º about the point (1, 1, 0) the matrix becomes

x′ 0 –1 0 2 x
y′ = 1 0 0 0 y
z′ 0 0 1 0 z
1 0 0 0 1 1 18
Example: Coordinate Transformation (Rotation in 3D) V.V.I.
Determine the new coordinate P′ of a point P(120, 30, 80) after rotating 300 across Z-axis.
Assume that the center of rotation is C(30, -40, 50).
Solution:
Subrtract C(30, -40, 50) from P(120, 30, 80) to get P1. This enables us to perform the
rotation about the origin.
x1 = 120 – 30 = 90
y1 = 30 – (-40) = 70
z1 = 80 – 50 = 30
Rotate P1 , 300 about the origin across Z-axis to get P2 :
x2 = 90 cos 300 – 70 sin 300 = 42.94
y2 = 90 sin 300 + 70 cos 300 = 105.62
z2 = 30
Add C(30, -40, 50) to to get P′ (compensate for the original subtraction)
x′= 42.94 + 30 = 72.94
y′= 105.62 + (-40) = 65.62
z′= 30 + 50 = 80 Ans. 19
Multiple Rotations in 3D
• Product of 3 consecutive rotations (e.g., around X-Y-Z axes)
• Roll-pitch-yaw convention is very common in aerial navigation
Rotation across X-axis = ROLL
Rotation across Y-axis = PITCH
Rotation across Z-axis = YAW

Pitch: changing DIRECTION


+y

Roll: going UP & DOWN

+z

Yaw: for TILTING


+x
20
Roll-Pitch-Yaw Convention
X Y Z -axis rotation.
• Roll , Pitch , Yaw ,
• Conversion to 33 rotation matrix:

21
Multiple rotation in co-ordinate transformation
Roll , Pitch , Yaw , and center of rotation is (a, b, c)
Conversion to 44 rotation matrix: R = T · Rz() · Ry() · Rx() · -T
rotation across z-axis rotation across y-axis
rotation across x-axis
x' 1 0 0 a Cos  –Sin  0 0 Cos  0 Sin  0 1 0 0 0 1 0 0 –a x

y' = 0 1 0 b . Sin  Cos  0 0 . 0 1 0 0 . 0 Cos  –Sin  0 . 0 1 0 –b . y

z' 0 0 1 c 0 0 1 0 –Sin  0 Cos  0 0 Sin  Cos  0 0 0 1 –c z

1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1

Positive Translation Negative Translation


(returning from the origin (going towards origin)
to the original position) input
output 22
Reflection
A reflection can be seen in water, in a mirror, in glass, or in a shiny
surface. An object and its reflection have the same shape and size,
but the figures face in opposite directions. In a mirror, for example,
right and left are switched.
A line of reflection FLIPS!!!
Reflection
The line (where a mirror may be placed) is called the line of
reflection. The distance from a point to the line of reflection is the
same as the distance from the point's image to the line of reflection.
A reflection can be thought of as a "flipping" of an object over the line of
reflection.

line of reflection
If you folded the two shapes together the two shapes would overlap exactly!
What happens to points in a Reflection?
• Name the points of the original triangle.
A (2,-3) B (5,-4) C (2,-4)
• Name the points of the reflected triangle.
A' (2,3) B' (5,4) C' (2,4)
• What is the line of reflection? x-axis

• How did the points change from the original


to the reflection? The sign of y switches

• (For the case of 3D), What will be x' 1 0 0 x


the plane of reflection? xz plane y' = 0 -1 0 y
1 0 0 1 1

You might also like