30
IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker

3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

3D Geometric

TransformationChapt. 5 in FVD, Chapt. 11 in Hearn & Baker

Page 2: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

3D Coordinate Systems

• Right-handed coordinate system:

• Left-handed coordinate system:

y

z

x

x

y

z

Page 3: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

Reminder: Vector Product

U

V

UxV

VxU

sinˆ VUnVU

xyyx

zxxz

yzzy

zyx

zyx

vuvu

vuvu

vuvu

vvv

uuu

zyx

VU

ˆˆˆ

Page 4: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

3D Point

• A 3D point P is represented in

homogeneous coordinates by a

4-dim. vector:

• Note, that

1

z

y

x

P

z

y

x

z

y

x

p

1

Page 5: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

3D Transformations

• In homogeneous coordinates, 3D

Affine transformations are

represented by 4x4 matrices:

• A point transformation is

performed:

1000

z

y

x

tihg

tfed

tcba

110001

'

'

'

z

y

x

tihg

tfed

tcba

z

y

x

z

y

x

Page 6: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• Given k points (P1,P2,..Pk) that have

been transformed to (P'1,P'2,..,P'k) by

the 3D affine transformation. How

many points uniquely define the

transformation?

• How can we find the transformation?

A

1

1

1

111

111

111

100000000

010000000

001000000

z

y

x

t

t

t

i

h

g

f

e

d

c

b

a

zyx

zyx

zyx

z

y

x

Page 7: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

3D Translation

• P in translated to P' by:

• Inverse translation:

11

'

'

'

11000

100

010

001

z

y

x

z

y

x

tz

ty

tx

z

y

x

z

y

x

t

t

t

'PPT Or

z

yx

PPT '1

Page 8: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

11

'

'

'

11000

000

000

000

cz

by

ax

z

y

x

z

y

x

c

b

a

'PPS Or

Scaling

PPS '1

y

z

xy

z

x

Page 9: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• A reflection through the xy plane:

• Reflections through the xz and the

yz planes are defined similarly.

• How can we reflect through some

arbitrary plane?

3D Reflection

111000

0100

0010

0001

z

y

x

z

y

x

Page 10: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• Shearing:

• The change in each coordinate

is a linear combination of all

three.

• Transforms a cube into a

general parallelepiped.

3D Shearing

111000

01

01

01

zfyex

dzycx

bzayx

z

y

x

fe

dc

ba

Page 11: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

3D Rotation

• To generate a rotation in 3D we

have to specify:

– axis of rotation (2 d.o.f)

– amount of rotation (1 d.o.f)

• Note, the axis passes through the

origin.

x

y

z

Page 12: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• A counter-clockwise rotation

about the z-axis:

1zyx

1000010000θcosθsin00θsinθcos

1'z'y'x

y

z

x

pRp z )('

Page 13: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

11000

0cossin0

0sincos0

0001

1

'

'

'

z

y

x

z

y

x

pRp x )('

• A counter-clockwise rotation

about the x-axis:

y

z

x

Page 14: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• A counter-clockwise rotation

about the y-axis:

11000

0cos0sin

0010

0sin0cos

1

'

'

'

z

y

x

z

y

x

pRp y )('

y

z

x

Page 15: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

Inverse Rotation

)(')(')(1 TRpRpRp

Composite Rotations

• Rx, Ry, and Rz, can perform any

rotation about an axis passing

through the origin.

Page 16: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

Composition of

Transformations

• Rigid transformation:

– Translation + Rotation (distance

preserving).

• Similarity transformation:

– Translation + Rotation + uniform

Scale (angle preserving).

• Affine transformation:

– Translation + Rotation + Scale +

Shear (parallelism preserving).

• All above transformations are groups

where Rigid Similarity Affine.

Page 17: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

Rigid

Affine

Similarity

Page 18: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

Changing Coordinate

Systems

• Problem: Given the XYZ orthogonal

coordinate system, find a

transformation, M, that maps a

representation in XYZ to representation

in orthogonal system UVW, with the

same origin.

• The matrix M transforms the UVW

vectors to the XYZ vectors.

y

z

x

u=(ux,uy,uz)

v=(vx,vy,vz)

w=(wx,wy,wz)

Page 19: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• Solution: M is rotation matrix

whose rows are U,V, and W:

• Note, the inverse transformation is

the transpose:

1000

0www

0vvv

0uuu

Mzyx

zyx

zyx

1000

0wvu

0wvu

0wvu

MMzzz

yyy

xxx

T1

Page 20: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• Let's check the transformation

of U under M:

• Similarly, V goes into Y, and W

goes into Z.

X

1001

100

uuu

1

u

u

u

1000

0www

0vvv

0uuu

MU

2z

2y

2x

z

y

x

zyx

zyx

zyx

Page 21: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

U

1

u

u

u

1001

1000

0wvu

0wvu

0wvu

1001

Mz

y

x

zzz

yyy

xxx

1

• Let's check the transformation

of the X axis under M-1:

• Similarly, Y goes into V, and Z

goes into W.

Page 22: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

Rotation About an

Arbitrary Axis

• Axis of rotation can be located at

any point: 6 d.o.f.

• The idea: make the axis

coincident with one of the

coordinate axes (z axis), rotate by

, and then transform back.

• Assume that the axis passes

through the points p1 and p2.

y

z

x

p1

p2

Page 23: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

y

zx

p1

y

x

p1

y

x

p1

z

z

step 1

Initial Position

Translate p1 to the Origin

step 2

Rotate p2 onto the z Axis

p2

p2

p2

y

x

p1

z

step 3

Rotate the Object

Around the z Axis

p2

x

p1

z

step 4

Rotate the Axis to the

original Orientation

p2

y

zx

p1

step 5

Translate to the

Original Position

p2

Page 24: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• Constructing an orthogonal

system along the rotation axis:

– A vector W parallel to the rotation

axis:

– A vector V perpendicular to W:

– A vector U forming a right-handed

orthogonal system with W and V:

ssw;pps 12

a

avwa

;

1

0

0

wvu

Page 25: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• Step1:

• Step2:

• Step3:

1000

z100

y010

x001

T1

1

1

1000

0www

0vvv

0uuu

Mzyx

zyx

zyx

1000010000θcosθsin00θsinθcos

R

Page 26: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• Step4:

• Step5:

1000

0wvu

0wvu

0wvu

Mzzz

yyy

xxx

1

1000

z100

y010

x001

T1

1

1

1

PTMRMTP 11

Rotating P about an axis:

Page 27: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

Transforming Planes

• Plane representation:

– By three non-collinear points

– By implicit equation:

0

1

z

y

x

DCBADCzByAx

P0

P1P2

1zyx

1

D

C

D

B

D

A

Page 28: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• One way to transform a plane is

by transforming any three non-

collinear points on the plane.

• Another way is to transform the

plane equation: Given a

transformation T that

transforms [x,y,z,1] to [x',y',z',1]

find [A',B',C',D'], such that:

0

1

'

'

'

''''

z

y

x

DCBA

Page 29: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

• Note that

• Thus, the transformation that

we should apply to the plane

equation is:

0

1zyx

TTDCBA 1

1TDCBADCBA

Page 30: 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric Transformation Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker. IDC-CG 3D Coordinate Systems

IDC-CG

4Theoretical Homework #

1. Find the transformation matrix (homogeneous coordinates) that flips an object about a plane whose normal is directed towards (-2 2 0), and intersects the y-axis at y=2.

2. Find the matrix that performs a rotation by rad. about a rotation axis (a b c). Assume |(a b c)|=1. Note, that the rotation pivot is at the origin.

3. Given 2 points p1=(1 0 3) and p2=(3 1 0). The distances of these points to the origin are identical. Based on the previous answer, find the rotation matrix that brings p1 towards p2.

(-2 2 0)

x

y

z

2