03 2D-3D Geometry
03 2D-3D Geometry
• Scaling
• Rotation
• Shear
• Translation
Mathematical
representation
sx
img = cv2.imread('messi5.jpg',0)
rows,cols = img.shape
M = np.float32([[1,0,100],[0,1,50]])
dst = cv2.warpAffine(img,M,(cols,rows))
cv2.imshow('img',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
replace 2d points with 3d points, last
coordinate 1
Translation components
Full-generality 3 x 3 homogeneous
transformation is called a homography
Scale/rotation components
Full-generality 3 x 3 homogeneous
transformation is called a homography
Shear/rotation components
Full-generality 3 x 3 homogeneous
transformation is called a homography
x
y
z
A 3D point P is represented in
homogeneous coordinates by a 4-dim. Vect:
x
y
P
z
1
We don't lose anything
x
The main advantage: it is easier to y
compose translation and rotation
Everything is matrix multiplication z
1
Right Hand Left Hand coordinate
coordinate system: system:
In homogeneous coordinates, 3D
transformations are represented by 4×4
matrixes:
a b c t
x
d e f t
y
g h i t
z
0 0 0 1
3D Translation
P is translated to P' by:
x 1 0 0 tx x
y 0 1 0 t y y
z 0 0 1 tz z
1 0 0 0 1 1
P T P
An object is translated in 3D dimensional by
transforming each of the defining points of the
objects .
An Object represented as a set of polygon surfaces, is translated
by translate each vertex of each surface and redraw the polygon
facets in the new position.
Inverse Translation:
T (t , t , t ) T (t ,t ,t )
1
x y z x y z
3D Rotation
In general, rotations are specified by a
rotation axis and an angle. In
two-dimensions there is only one
choice of a rotation axis that leaves
points in the plane.
The easiest rotation axes are those that parallel to the
coordinate axis.
Positive rotation angles produce counterclockwise rotations
about a coordinate axix, if we are looking along the positive half
of the axis toward the coordinate origin.
Coordinate Axis
Rotations
Z-axis rotation: For z axis same as 2D rotation:
x' cos sin 0 0 x
y ' sin cos 0 0 y
z' 0 0 1 0 z
1 0 0 0 1 1
P R z (θ ) P
X-axis rotation:
x ' 1 0 0 0 x
y ' 0 cos sin 0 y
z ' 0 sin cos 0 z
1 0 0 0 1 1
P R x ( ) P
Y-axis rotation:
x' cos 0 sin 0 x
y ' 0 1 0 0 y
z ' sin 0 cos 0 z
1 0 0 0 1 1
P R ( ) P
y
Other way to look at
rotation
Roll, Pitch, Yaw
Imagine three lines running through an
airplane and intersecting at right
angles at the airplane's center of
gravity.
Roll: rotation around the front-to-back
axis.
PITCH: Rotation around the side-to-side
axis
YAW: Rotation around the vertical axis.
An Example of the
Airplane
Consider the following example. An airplane is oriented
such that its nose is pointing in the positive z direction,
its right wing is pointing in the positive x direction, its
cockpit is pointing in the positive y direction. We want
to transform the airplane so that it heads in the direction
given by the vector DOF (direction of flight), is centre
at P, and is not banked.
3D Scaling
About origin: Changes the size of the object and
repositions the object relative to the coordinate origin.
x s x 0 0 0 x
y 0 sy 0 0 y
z 0 0 sz 0 z
1 0 0 0 1 1
P S P
Composite
3D Transformations
Multiply matrices
Rightmost term in matrix product is the first
transformation to be applied
Rotation axis parallel with coordinate axis (Example x axis):
P T 1
R x (θ ) T P
An arbitrary axis (with the rotation axis projected onto the Z
axis):
R ( ) T 1 R x 1 ( ) R y1 ( ) R z ( ) R y ( ) R x ( ) T
To compose transformations, multiply
the matrices:
• composition of a rotation and a translation:
M = RT
all transformations can be expressed
as matrices
• even transformations that are not
translations, rotations and scaling
Rotation about a point Q:
• translate Q to origin (TQ),
• rotate about origin (R)
• translate back to Q (- TQ).
P’=(-TQ)RTQ P