3D Transformation.pdf

23
        3D Transformations  Translation  Rotation  Scaling  Composite transformations  Reection and shear  Coordinate system transformations  OpenGL transformation functions 1

Transcript of 3D Transformation.pdf

Page 1: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 1/23

'

&

   $

   %

3D Transformations

• Translation

• Rotation

• Scaling

• Composite transformations

• Reflection and shear

• Coordinate system transformations

• OpenGL transformation functions

1

Page 2: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 2/23

'

&

   $

   %

3D Transformations

• All the 2D transformations can be extended to three dimensions

• Translation and Scaling are extended by adding a third value for the z-direction

• Rotation in 3D is more complicated

• Homogeneous coordinates for 3 dimensions require 4 components.

• Any sequence of transformations can be represented as a composite of the

individual transformations.

2

Page 3: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 3/23

'

&

   $

   %

3D Translation

• Represent a 3D translation by a 3-tuple whose components are the shifts in

the x, y and z directions. (tx, ty, tz)

x = x + tx

y = y + ty

z = z + tz

x

y

z

(x, y, x)(x’, y’, z’)

T = (tx, ty, tz)

3

Page 4: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 4/23

'

&

   $

   %

• In matrix form, this is

x

y

z

1

=

1 0 0 tx

0 1 0 ty

0 0 1 tz

0 0 0 1

·

xy

z

1

or

P = T · P

4

Page 5: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 5/23

'

&

   $

   %

3D Rotation

• Can rotate about any arbitrary line in space.

• Easiest to visualize are rotations about one of the coordinate axes

• 2D rotation is equivalent to a 3D rotation about the z-axis

• A positive rotation about a coordinate axis is counterclockwise when viewedfrom the positive direction.

y

x

z

5

Page 6: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 6/23

'

&

   $

   %

Rotation about Coordinate Axis

• For a rotation about the z-axis, the x and y coordinates change in the same

way as for a 2D rotation and the z coordinate is unchanged.

x = x cos θ−

y sin θ

y = x sin θ + y cos θ

z = z

x

y

z

1

=

cos θ − sin θ 0 0

sin θ cos θ 0 0

0 0 1 0

0 0 0 1

·

x

y

z

1

• Rotations about other coordinate axes have a similar form.

6

Page 7: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 7/23

'

&

   $

   %

Cyclic Permutations

We can generate the matrices by doing a cyclic permutation of the coordinate

parameters.

x → y → z → x

y

x

z

z

zx

x

y

y

7

Page 8: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 8/23

'

&

   $

   %

Rotation about x and y Axes

• For a rotation about the x-axis, we get

y = y cos θ − z sin θ

z = y sin θ + z cos θ

x = x

• For a rotation about the y-axis, we get

z = z cos θ − x sin θ

x = z sin θ + x cos θ

y = y

• As in 2D, the inverse transformation can be obtained by replacing θ by −θ.

As before,

R−1 = R

8

Page 9: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 9/23

'

&

   $

   %

Rotation About Line Parallel to Axis

• Do this with a composite transformation1. Translate rotation axis to coordinate axis

2. Rotate

3. Reverse the translation

• The composite transformation matrix is

R(θ) = T−1

Rx(θ) T

9

Page 10: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 10/23

'

&

   $

   %

Transformation Sequence

translate

inverse

translation

 r o  t a  t

  i o n

10

Page 11: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 11/23

'

&

   $

   %

Rotation about an Arbitrary Line

•Use the same general approach but need both a translation and a rotation to

align

• Transformation sequence:

1. Translate rotation axis to intersect the origin

2. Rotate axis of rotation to align with a coordinate axis

3. Do the desired rotation about the coordinate axis

4. Reverse the rotation in step 2

5. Reverse the translation in step 1

11

Page 12: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 12/23

'

&

   $

   %

Transformation Sequence

P1

P2

P1’

P2’

P1’

P2’

P1

P2

P1’

P2’’

P1’

P2’’

12

Page 13: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 13/23

'

&

   $

   %

Specifying a Rotation Axis

• Rotation axis can be defined by two

points

P1

P2

u

• Use these points to generate a vec-

tor

V = P2 − P1

= (x2 − x1, y2 − y1, z2 − z1)

• Now construct a unit rotation axis

vector

u = V

|V|

= (a,b,c)

where a = x1−x2|V| , b = y1−y2

|V| and

c = z1−z2|V|

13

Page 14: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 14/23

'

&

   $

   %

Translation to the Coordinate Origin

u

T =

1 0 0

−x1

0 1 0 −y1

0 0 1 −z1

0 0 0 1

14

Page 15: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 15/23

'

&

   $

   %

Aligning Rotation and Coordinate Axes

• In general, need two coordinate axis rotations to accomplish this alignment.

• One of several possible sequences

1. Rotate rotation axis about x-axis into x-z plane

2. Rotate about y-axis to align with z-axis

u = (a,b,c)

uz= (0,0,1)

u’= (0, b, c)

αααα

u’’ = (a,0,d)uz= (0,0,1)

15

Page 16: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 16/23

'

&

   $

   %

Rotation Angles

• α is the angle between the projection of  u onto the y-z plane and the z-axis

• β  is the angle between the projection of  u onto the x-z plane and the z-axis

• Use dot and cross products to determine the sin and cos terms needed for the

rotation matrices.

– u · v = |u| |v| cos θ

– u × v = |u| |v| sin θ

Rx(α) =

1 0 0 0

0 cd

− bd

0

0 bd

cd

0

0 0 0 1

· Rx(α) =

d 0 −a 0

0 1 0 0

a 0 d 0

0 0 0 1

·

where a, b and c are as defined earlier and d =

√ b

2

+ c

2

16

Page 17: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 17/23

'

&

   $

   %

3D Scaling

• Similar to those in 2D

•A 3D scaling matrix

sx 0 0 0

0 sy 0 0

0 0 sz 0

0 0 0 1

• Example: Scaling relative to a fixed

point

(xf, yf, zf) (xf, yf, zf)

(xf, yf, zf) (xf, yf, zf)

translate

scale

inverse

translation

17

Page 18: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 18/23

'

&

   $

   %

3D Reflection

• Reflection can be performed relative to a reflection axis or relative to a plane

• Reflection relative to a line is effectively a 180 deg rotation about that line

• Reflection relative to a plane is like a rotation in 4D - it is like a conversion

between left-handed and right-handed coordinate systems.

reflectionrelative tox-y plane

z

x

y

x

z

y

18

Page 19: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 19/23

'

&

   $

   %

3D Shear

• Shear transformations are used for modifying shapes and for perspective trans-

formations

• Similar to shearing in 2D for x and y-axis shears; can also have z-axis shear.

• A z-axis shearing matrix

1 0 shzx −shzx · zref 0 1 shzy −shzy · zref 0 0 1 0

0 0 0 1

·

• Example: shzx = shzy = 1 a nd

zref  = (0, 0, 0)

shear

19

Page 20: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 20/23

'

&

   $

   %

Affine Transformation

• Transformations of the form

x = axx x + axy y + axz z

y = ayx x + ayy y + ayz z

z = azx x + azy y + azz z

• Parallel lines remain parallel.

• Finite points map to finite points.

• Any affine transformation can be expressed in terms of translation, rotation,

scaling, reflection and shear.

20

Page 21: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 21/23

'

&

   $

   %

Coordinate Transformations

• Scene processing in computer graphics involves transformations between dif-

ferent coordinate systems.

– Conversions between world and device coordinates

– Objects are often modeled in their own coordinate system

– Objects that are created from many simpler objects need coordinate trans-

formations to properly orient the components.

• Two steps to this transformation in 2D

1. Translate the origin of one system to that of the other

2. Rotate to align the x-axes

21

Page 22: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 22/23

'

&

   $

   %

Specifying a 2D Coordinate System

• There are several ways of specifying one coordinate system relative to another

one

– With the position of the origin and the angle between the x and x axes

– With the position of the origin and a vector in the direction of the y axis

– With the coordinates of two points

θ

y axis

x axis

 x ’  a x i s y ’

  a x i s

y0

x0

y axis

x axis

 x ’  a x i s y ’

  a x i s

y0

x0

 V 

P0

y axis

x axis

 x ’  a x i s y ’

  a x i s

y0

x0

P0

P1

22

Page 23: 3D Transformation.pdf

7/27/2019 3D Transformation.pdf

http://slidepdf.com/reader/full/3d-transformationpdf 23/23

'

&

   $

   %

3D Coordinate Transformations

• In 3D, need the equivalent of two orthogonal vectors to specify a coordinate

system. (The third one is determined by the cross product of the original

two.)

uz’=u

uy’

ux’

• Can use a coordinate system whose z-axis is the rotation axis to derive the

transformation matrix for rotation about an arbitrary axis.

23