1 Translation and Scalling Matrice Translation o The translation - - PDF document

1
SMART_READER_LITE
LIVE PREVIEW

1 Translation and Scalling Matrice Translation o The translation - - PDF document

3D Coordinate Systems 3D Transformation o The translation, scaling and rotation transformations used for 2D o 3D computer graphics involves the additional dimension of can be extended to three dimensions depth, allowing more realistic


slide-1
SLIDE 1

1

3D Coordinate Systems

  • 3D computer graphics involves the additional dimension of

depth, allowing more realistic representations of 3D objects in the real world

  • There are two possible ways of “attaching” the Z-axis, which

gives rise to a left-handed or a right-handed system

3D Transformation

  • The translation, scaling and rotation transformations used for 2D

can be extended to three dimensions

  • In 3D, each transformation is represented by a 4x4 matrix
  • Using homogeneous coordinates it is possible to represent each

type of transformation in a matrix form and integrate transformations into one matrix

  • To apply transformations, simply multiply matrices, also easier in

hardware and software implementation

  • Homogeneous coordinates can represent directions
  • Homogeneous coordinates also allow for non-affine

transformations, e.g., perspective projection

Homogeneous Coordinates

  • In 2D, use three numbers to represent a point
  • (x,y) = (wx,wy,w) for any constant w≠0
  • To go backwards, divide by w, (x,y) becomes (x,y,1)
  • Transformation can now be done with matrix multiplication

                    =           ′ ′ 1 1 1 y x b a a b a a y x

y yy yx x xy xx

Basic 2D Transformations

  • Translation:
  • Scaling:
  • Rotation:

          1 1 1

y x

b b           1

y x

s s           − 1 cos sin sin cos θ θ θ θ

slide-2
SLIDE 2

2

Translation and Scalling Matrice

  • The translation and scaling transformations may

be represented in 3D as follows: 1 0 0 trX 0 1 0 trY 0 0 1 trZ 0 0 1 SX 0 0 0 SY 0 0 0 SZ 0 0 1

Translation matrix Scaling matrix

Translation

translation along y,

  • r V = (0, k, 0)
  • riginal

V=(ai + bj +ck) == (a, b, c)

Scaling

Original scale all axes scale Y axis

  • ffset from origin

                        =             ′ ′ ′ 1 1 1 z y x c b a z y x

3D Shearing

                        =             ′ ′ ′ 1 1 1 1 1 1 z y x f e d c b a z y x

Shearing: The change in each coordinate is a linear combination of all three Transforms a cube into a general parallelepiped

slide-3
SLIDE 3

3

Rotation

  • In 2D, rotation is about a point
  • In 3D, rotation is about a vector, which can be done through

rotations about x, y or z axes

  • Positive rotations are anti-clockwise, negative rotations are

clockwise, when looking down a positive axis towards the

  • rigin

x y z x y z x y z

Major Axis Rotation Matrices

  • about X axis
  • about Y axis
  • about Z axis

            − = 1 1 θ θ θ θ cos sin sin cos

x

R             − = 1 1 θ θ θ θ cos sin sin cos

z

R             − = 1 1 θ θ θ θ cos sin sin cos

y

R Rotations are

  • rthogonal matrices,

preserving distances and angles.

Rotation

rotation of 45o about the Z axis

  • ffset from origin translation then rotate about Z axis

Rotation Axis

  • In general rotation vector does not pass through
  • rigin
slide-4
SLIDE 4

4

Rotation about an Arbitrary Axis

  • Rotation about an Arbitrary Axis

Basic Idea

1. Translate (x1, y1, z1) to the origin 2. Rotate (x’2, y’2, z’2) on to the z axis 3. Rotate the object around the z-axis 4. Rotate the axis to the original

  • rientation

5. Translate the rotation axis to the

  • riginal position

Basic Idea

1. Translate (x1, y1, z1) to the origin 2. Rotate (x’2, y’2, z’2) on to the z axis 3. Rotate the object around the z-axis 4. Rotate the axis to the original

  • rientation

5. Translate the rotation axis to the

  • riginal position

(x2,y2,z2) (x1,y1,z1) x z y

R-1 R-1 T-1 T-1 R R T T

( ) ( ) ( ) ( ) ( )

] ][ ][ ][ [ ] [ ] [ ] [ ] [

1 1 1

R x y z y x R arb

T R R R R R T R

T T T T T T T T

α φ θ φ α − − −

=

Rotation about an Arbitrary Axis

  • Step 1. Translation

            − − − = 1 1 1 1

1 1 1

z y x T

R

T

(x2,y2,z2) (x1,y1,z1) x z y

Rotation about an Arbitrary Axis

  • Step 2. Establish

[ ]

            − =             − = 1 / / / / 1 1 cos sin sin cos 1

) (

d c d b d b d c T

x

R

α α α α

α

(a,b,c) (0,b,c)

Projected Point

α α

Rotated Point

d c c b c d b c b b = + = α = + = α

2 2 2 2

cos sin

x y z

[ ]

) (α

x

R

T

Rotation about an Arbitrary Axis

  • Step 3. Rotate about y axis by φ

(a,b,c) (a,0,d) φ l d

2 2 2 2 2 2 2 2

cos , sin c b d d a c b a l l d l a + = + = + + = = φ = φ

( )

[ ]

            − =             − = 1 / / 1 / / 1 cos sin 1 sin cos l d l a l a l d T

y

R

φ φ φ φ

φ

x y

Projected Point

z

Rotated Point

slide-5
SLIDE 5

5

Rotation about an Arbitrary Axis

  • Step 4. Rotate about z axis by the desired angle θ

θ l

( )

[ ]

            − = 1 1 cos sin sin cos θ θ θ θ

θ

z

R

T

y x z

Rotation about an Arbitrary Axis

  • Step 5. Apply the reverse transformation to place the axis back in

its initial position

x y l l z

( ) ( )

            −             −             =

− − −

1 cos sin 1 sin cos 1 cos sin sin cos 1 1 1 1 1 ] [ ] [ ] [

1 1 1 1 1 1

φ φ φ φ α α α α

φ α

z y x T T T

y x R

R R T

( ) ( ) ( ) ( ) ( )

] ][ ][ ][ [ ] [ ] [ ] [ ] [

1 1 1

R x y z y x R arb

T R R R R R T R

T T T T T T T T

α φ θ φ α − − −

=

Rotation about an Arbitrary Axis

Find the new coordinates of a unit cube 90º-rotated about an axis defined by its endpoints A(2,1,0) and B(3,3,1).

Rotation about an Arbitrary Axis

  • Step1. Translate point A (2,1,0) to the origin

A’(0,0,0)

x z y

B’(1,2,1)

            − − = 1 1 1 1 2 1 ] [

R

T

T

slide-6
SLIDE 6

6

Rotation about an Arbitrary Axis

x z y l

( )

[ ]

                − = 1 5 5 5 5 2 5 5 2 5 5 1

α

x

R

T 6 1 2 1 5 5 5 1 cos 5 5 2 5 2 1 2 2 sin

2 2 2 2 2

= + + = = = α = = + = α l

B’(1,2,1)

α

Projected point (0,2,1) B”(1,0,√5)

  • Step 2. Rotate axis A’B’ about the x axis by and angle α, until it lies
  • n the xz plane.

Rotation about an Arbitrary Axis

x z y l

( )

[ ]

                − = 1 6 30 6 6 1 6 6 6 30

φ

y

R

T 6 30 6 5 cos 6 6 6 1 sin = = φ = = φ φ

B”(1,0, √ 5) (0,0,√6)

  • Step 3. Rotate axis A’B’’ about the y axis by and angle φ,

until it coincides with the z axis.

Rotation about an Arbitrary Axis

( )

[ ]

            − =

°

1 1 1 1

90

z

R

T

Finally, the concatenated rotation matrix about the arbitrary axis AB becomes,

  • Step 4. Rotate the cube 90° about the z axis

( ) ( )

( )

( ) ( )

] ][ ][ ][ [ ] [ ] [ ] [ ] [

90 1 1 1

R x y z y x R arb

T R R R R R T R

T T T T T T T T

α φ φ α

− −

=

Rotation about an Arbitrary Axis

            − − − =             − −                 −                 −             −                 −                 −             = 1 560 . 167 . 741 . 650 . 151 . 1 075 . 667 . 742 . 742 . 1 983 . 075 . 166 . 1 1 1 1 2 1 1 5 5 5 5 2 5 5 2 5 5 1 1 6 30 6 6 1 6 6 6 30 1 1 1 1 1 6 30 6 6 1 6 6 6 30 1 5 5 5 5 2 5 5 2 5 5 1 1 1 1 1 2 1 ] [

arb

R

T

slide-7
SLIDE 7

7

Rotation about an Arbitrary Axis

[ ] [ ] [ ]

P T P

arb

R ⋅

=

*

[ ]

            − − − − − − − =                         − − − = 1 1 1 1 1 1 1 1 076 . 091 . 560 . 726 . 817 . 650 . 301 . 1 467 . 1 483 . 409 . 151 . 1 225 . 1 184 . 258 . 484 . 558 . 891 . 2 909 . 1 742 . 1 725 . 2 816 . 2 834 . 1 667 . 1 650 . 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 560 . 167 . 741 . 650 . 151 . 1 075 . 667 . 742 . 742 . 1 983 . 075 . 166 .

*

P

  • Multiplying [TR]AB by the point matrix of the original cube

Rotation about an Arbitrary Axis

  • Reflection Relative to the xy Plane
  • Z-axis Shear

x z y x z y

                        − =             1 1 1 1 1 1 z y x z y x ' ' '                         =             1 1 1 1 1 1 ' ' ' z y x b a z y x

Q1 - Translate by <1, 1, 1>

  • A translation by an offset (tx, ty, tz) is achieved

using the following matrix:

  • So to translate by a vector

(1, 1, 1), the matrix is simply:             = 1 1 1 1 ) , , (

z y x z y x T

t t t t t t M

            = 1 1 1 1 1 1 1 ) 1 , 1 , 1 (

T

M

Q2- Rotate by 45 degrees about x axis

  • So to rotate by 45 degrees about the x-axis, we

use the following matrix:

                − =             − = 1 2 1 2 1 2 1 2 1 1 1 45 cos 45 sin 45 sin 45 cos 1 ) 45 (

x

R

slide-8
SLIDE 8

8

Q3 - Rotate by 45 about axis <1, 1, 1>

  • So a rotation by 45 degrees about <1, 1, 1> can

be achieved by a few succesive rotations about the major axes. Which can be represented as a single composite transformation 414 . 1 2

2 2

= = + =

z x

n n d 45 1 1 tan tan

1 1

= = =

− − z x

n n α 264 . 35 2 1 tan tan

1 1

= = =

− −

d n y β nx = 1 ny = 1 nz = 1 SO

Q3 - Arbitrary Axis Rotation

  • The composite transformation can then be
  • btained as follows:

) ( ) ( ) ( ) ( ) ( ) 1 , 1 , 1 (

1 1

α β θ β α

y x z R

R R R R R M

x y

  • =

− −             − 1 1 ) 45 cos( ) 45 sin( ) 45 sin( ) 45 cos(             − − − − − 1 ) 45 cos( ) 45 sin( 1 ) 45 sin( ) 45 cos(             − 1 ) 2 . 35 cos( ) 2 . 35 sin( ) 2 . 35 sin( ) 2 . 35 cos( 1             − − − − − 1 ) 2 . 35 cos( ) 2 . 35 sin( ) 2 . 35 sin( ) 2 . 35 cos( 1

            − 1 ) 45 cos( ) 45 sin( 1 ) 45 sin( ) 45 cos(

=

?? x y z

Directions vs. Points

  • We have looked at transforming points
  • Directions are also important in graphics
  • Viewing directions
  • Normal vectors
  • Ray directions
  • Directions are represented by vectors, like points, and can

be transformed, but not like points

  • Say we define a direction as the difference of two points:

d=a–b. This represents the direction of the line between two points

  • Now we translate the points by the same amount:

a’=a+t, b’=b+t

  • Have we transformed d?

(1,1) (-2,-1)

Homogeneous Directions

  • Translation does not affect directions!
  • Homogeneous coordinates give us a clear way of handling

this, e.g., direction (x,y) becomes homogeneous direction (x,y,0), and remains the same after translation:

  • (x, y, 0) is a vector, (x,y,1) is a point.
  • The same applies to rotation and scaling, e.g., scaling

changes the length of vector, but not direction

  • Normal vectors are slightly different though (can’t always

use the matrix for points to transform the normal vector)

          =                     1 1 1 y x y x b b

y x

slide-9
SLIDE 9

9

Alternative Rotations

  • Specify the rotation axis and the angle (OpenGL method)
  • Euler angles: Specify how much to rotate about X, then how

much about Y, then how much about

  • These are hard to think about, and hard to compose
  • Quaternions
  • 4-vector related to axis and angle, unit magnitude, e.g.,

rotation about axis (nx,ny,nz) by angle θ:

  • Only normalized quaternions represent rotations, but you can

normalize them just like vectors, so it isn’t a problem

  • But we don’t want to learn all the maths about quaternions in

this module, because we have to learn how to create a basic application before trying to make rotation faster

( ) ( ) ( ) ( )

( )

2 / sin , 2 / cos , 2 / cos , 2 / cos θ θ θ θ

z y x

n n n

OpenGL Transformations

  • OpenGL internally stores two matrices that control viewing
  • f the scene
  • The GL_MODELVIEW matrix for modelling and world to view

transformations

  • The GL_PROJECTION matrix captures the view to canonical

conversion

  • Mapping from canonical view volume into window space is through a

glViewport function call

  • Matrix calls, such as glRotate, glTranslate, glScale right

multiply the transformation matrix M with the current matrix C (e.g., identity matrix initially), resulting in CM - the last one is the first applied