Uploaded by simon.calabuig

VectorUses3dGraphing

advertisement
3D Geometric
Transformation
(Chapt. 5 in FVD, Chapt. 11 in Hearn & Baker)
3D Coordinate Systems
• Right-handed coordinate system:
z
y
x
• Left-handed coordinate system:
y
z
x
Reminder: Vector Product
UxV
V
θ
U
VxU
U × V = nˆ U V sin θ
xˆ
U ×V = u x
yˆ
uy
vx
vy
zˆ u y v z − u z v y 


u z = u z vx − u xvz 
v z  u x v y −u y v x 
3D Point
• A 3D point P is represented in
homogeneous coordinates by a
4-dim. vector:
 x
 y
P= 
z
 
1
• Note, that
 x  αx 
  α 
y
y
p= ≡ 
 z  αz 
   
1   α 
3D Transformations
• In homogeneous coordinates, 3D
transformations are represented by
4x4 matrices:
a b c tx 
d e f t 
y

g h i tz 


0 0 0 1 
• A point transformation is
performed:
 x '  a b
 '  d e
y  = 
 z '  g h
  
 1  0 0
c
f
i
0
tx  x
t y   y 
t z  z 
 
1  1 
3D Translation
• P in translated to P' by:
1
0

0

0
0 0 t x   x   x'  x + t x 
1 0 t y   y   y '  y + t y 
=
=
0 1 t z   z   z'  z + t z 
    

0 0 1  1   1   1 
Or
T P = P'
z
x
• Inverse translation:
y
T −1 P ' = P
Scaling
a
0

0

0
0 0 0  x   x ' ax 
b 0 0  y   y ' by 
=
=
0 c 0  z   z '   cz 
     
0 0 1  1   1   1 
S P = P'
Or
z
z
y
x
x
S −1 P ' = P
3D Shearing
• Shearing:
1

c
e

0
a
1
f
0
0  x   x + ay + bz 

  
0  y  cx + y + dz 
=
1 0  z   ex + fy + z 

  
0 1  1  
1

b
d
• The change in each coordinate
is a linear combination of all
three.
• Transforms a cube into a
general parallelepiped.
y
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.
y
z
x
• A counter-clockwise rotation
about the z-axis:
 x' cosθ
 y '  sin
 = θ
 z'  0
  
1  0
− sin θ
cosθ
0
0
0 0  x 
0 0  y 
1 0  z 
 
0 1  1 
p ' = R z (θ ) p
z
x
y
• A counter-clockwise rotation
about the x-axis:
0
 x '  1
 y ' 0 cos
θ
 =
 z '  0 sin θ
  
0
 1  0
0
− sin θ
cosθ
0
0  x 
0  y 
0  z 
 
1  1 
p ' = R x (θ ) p
z
y
x
• A counter-clockwise rotation
about the y-axis:
 x'  cosθ
 y '  0
 =
 z '   − sin θ
  
1  0
0 sin θ
1
0
0 cosθ
0
0
0  x 
0  y 
0  z 
 
1  1 
p ' = R y (θ ) p
z
x
y
Inverse Rotation
p = R −1 (θ ) p ' = R ( −θ ) p '
Composite Rotations
• Rx, Ry, and Rz, can perform any
rotation about an axis passing
through the origin.
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,
and then transform back.
• Assume that the axis passes
through the point p0.
z
p0
x
y
• Transformations:
– Translate P0 to the origin.
– Make the axis coincident with the
z-axis (for example):
• Rotate about the x-axis into the
xz plane.
• Rotate about the y-axis onto
the z-axis.
• Rotate as needed about the zaxis.
• Apply inverse rotations about y
and x.
• Apply inverse translation.
y
y
A
p0
D
x
x
z
p0
z
y
y
E
p0
p0
B
x
x
z
z
y
y
C
z
F
p0
x
z
p0
x
3D Reflection
• A reflection through the xy plane:
1
0

0

0
0  x   x 
0  y   y 
=
0  z   − z 
   
0  1   1 
0 0
1 0
0 −1
0 0
• Reflections through the xz and the
yz planes are defined similarly.
• How can we reflect through some
arbitrary plane?
Transforming Planes
• Plane representation:
– By three non-collinear points
– By implicit equation:
 x
 
y
Ax + By + Cz + D = [A B C D ]  = 0
z
 
1 
A
D

B
D
C 
1
D 
P1
[x
P0
P2
y z 1]
• One way to transform a plane is
by transforming any three noncollinear 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:
 x '
 y '
[A' B ' C ' D ']  = 0
z'
 
1
• Note that
[A
B
C
x
 
−1  y 
D ]T T
=0
z
 
1 
• Thus, the transformation that
we should apply to the plane
equation is:
 A' 
 B' 
  = T −1
C '
 
 D'
 A
 
T B
 
C 
 
D
( )
Changing Coordinate
Systems
• Problem: Given the XYZ
orthogonal coordinate system,
find a transformation, M, that
maps XYZ to an arbitrary
orthogonal system UVW.
• This transformation changes a
representation from the UVW
system to the XYZ system.
w=(wx,wy,wz)
z
(x0,y0,z0)
y
x
u=(ux,uy,uz)
v=(vx,vy,vz)
• Solution: M=RT where T is a
translation matrix by (x0,y0,z0), and
R is rotation matrix whose columns
are U,V, and W:
u x
u
R= y
u z

0
0
0
0

1
vx
vy
wx
wy
vz
0
wz
0
vx
wx
vy
wy
vz
wz
0
0
0 1  u x 
0 0 u y 
=
=U
0  0   u z 
   
1 1   1 
because
u x
u
RX =  y
u z

0
• Similarly, Y goes into V, and Z
goes into W.
• The inverse transform, T-1R-1,
provides the mapping from
UVW back to XYZ. For the
rotation matrix R-1=RT:
u x

v
RT U =  x
 wx

0
uy
uz
vy
wy
0
vz
wz
0
0 u x 
0 u y 
0  u z 
 
1  1 
u x2 + u 2y + u z2  1

  
0

 = 0 = X
=

 0
0

  
1

 1
• Comment: Very useful if an
arbitrary plane is to be mapped
to the XY plane or vice versa.
• Possible to apply if an arbitrary
vector is to be mapped to an
axis (How?).
Transformation Pipe-Line
Modeling
Coordinates
Modeling
Transformation
World Coordinates
Viewing
Transformation
Viewing Coordinates
Projection
Transformation
Projection Coordinates
Workstation
Transformation
Device Coordinates
Modeling Coordinate
Hierarchy
zw
world
xw
Tractor
System
Front-Wheel
System
World
transformation
Tractor
transformation
Front-wheel
yw
Download