3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric...
Transcript of 3D Geometric Transformationu.cs.biu.ac.il/~kapaho/CG/06_3d_trans.pdf · IDC-CG 3D Geometric...
IDC-CG
3D Geometric
TransformationChapt. 5 in FVD, Chapt. 11 in Hearn & Baker
IDC-CG
3D Coordinate Systems
• Right-handed coordinate system:
• Left-handed coordinate system:
y
z
x
x
y
z
IDC-CG
Reminder: Vector Product
U
V
UxV
VxU
sinˆ VUnVU
xyyx
zxxz
yzzy
zyx
zyx
vuvu
vuvu
vuvu
vvv
uuu
zyx
VU
ˆˆˆ
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
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
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
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
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
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
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
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
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 )('
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
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
IDC-CG
Inverse Rotation
)(')(')(1 TRpRpRp
Composite Rotations
• Rx, Ry, and Rz, can perform any
rotation about an axis passing
through the origin.
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.
IDC-CG
Rigid
Affine
Similarity
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)
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
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
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.
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
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
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
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
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:
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
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
IDC-CG
• Note that
• Thus, the transformation that
we should apply to the plane
equation is:
0
1zyx
TTDCBA 1
1TDCBADCBA
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