14 3D Transformations
T. Raghuveera
Objectives:
- To Understand the conventions for object transformations in 3D
- To Understand basic transformations in 3D, Translation, Rotation, Scaling
- To understand other transformations like Reflection, Shear
Discussion:
3D Transformations are mere extensions of 2D transformations, on most of the occasions, except for a few. In fact, the objects in the real world are in 3D, so, 2D is only a special case of 3D. All of the graphics API’s start with assumptions that, operations are performed in 3D, and by substituting 0 for the third coordinate (z), we get 2D.
Let’s first understand some important conventions for applying 3D transformations on objects. A coordinate system in 3D world is made up of 3 coordinate axes X, Y, Z in mutually perpendicular directions.
In a Right-Handed (RH) coordinate system as shown above, open the first 3 fingers of your right hand, orient them such that the thumb points at +ve X-direction (to the right side), Index finger points at the +ve Y-direction (upside), middle finger points at the +ve Z-direction (to yourself). In such an alignment, it is always that we see the world along the –ve Z-direction, as the +ve Z-direction is pointing towards self as shown in the figure below.
Image source: (http://what-when-how.com/wp-content/uploads/2011/08/tmpD54_thumb.jpg)
If we use our left-hand for representing a 3D coordinate system, as similar to that of the RH coordinate system, we call that a Left-Handed (LH) coordinate system, as shown below, where the Z– direction is away from the self and points in the opposite direction, with X and Y directions still being the same as that of the RH coordinate system.
Image source: (http://what-when-how.com/wp-content/uploads/2011/08/tmpD55_thumb.jpg)
With RH being the convention, that we shall follow, it should be always remembered that we see the world along the –ve Z-direction.
Basic Transformations in 3D:
Translation in 3D:
As similar to that of 2D Translation, 3D translation is represented using the following equations, with tx, ty, t z being the translational distances along the 3 coordinate axes respectively.
x’ = x + tx
y’ = y + ty
z’ = z + tz
The corresponding matrix representation in homogeneous form is given by
Rotation in 3D:
Rotation in 3D is complex, because, rotation is performed with respect to an axis of rotation (unlike 2D rotation which is about a pivot point) and the possible orientations of the objects and the axes about which the objects are rotated. It is also important to know the conventions for rotation for whether it is +ve or –ve. Rotations about an axis in counter clock-wise direction, when viewed along –ve direction of that axis are considered +ve.
3D rotation can be classified as ‘coordinate-axes rotations’, which are rotations performed about the standard coordinate axes, and ‘General 3D rotations’, which are performed about any general direction in space. Observe that, rotations about any axis (assuming standard axes), does not alter the corresponding coordinate, but alters the other coordinates, i.e., if we perform rotation about X-axis, the x-coordinate remains same after rotation, but y, z get altered.
• Coordinate-Axes Rotations
– X-axis rotation (pitch)
– Y-axis rotation (yaw)
– Z-axis rotation (roll)
• General 3D Rotations
– Rotation about an axis that is parallel to one of the coordinate axes
– Rotation about an arbitrary axis
Coordinate-Axes Rotations:
As shown in the figure below, rotation about X-axis is called, the ‘pitch’, rotation about Y-axis is called ‘yaw’ and rotation about Z-axis is called ‘roll’.
Z-axis rotation:
The equations for +ve rotation about Z-axis are given below.
x’ = x cosq – y sinq
y’ = x sinq + y cosq
z’ = z
The above equations can be represented in homogeneous matrix representation as below
P’ = Rz(θ).P
The matrix Rz(θ) represents rotation about Z-axis by an angle θ. It can be observed that, Z-axis rotation in 3D is same as that of 2D rotation about origin, except for the additional z-coordinate in 3D rotation, which is not altered after rotation.
Rotations about X, Y axes:
Follow this thumb rule to write eqs. for rotations with respect to X and Y axes.
x->y ->z ->x
which says that, in the equations for Z-axis rotation, replace x with y, y with z and z with x, we will get equations for rotations about X-axis and Y-axis after subsequent substitutions. Equations for rotation about X-axis can thus be obtained using the above thumb rule as
x’ = x
y’ = y cosθ – z sinθ
z’ = y sinθ + zcosθ
Equations for rotation about Y-axis can similarly be obtained using the above thumb rule and by substituting in the equations for rotation about X-axis we get
x’ = z sinθ + x cosθ
y’ = y
z’ = z cosθ – x sinθ
3D Rotation about an axis that is parallel to one of the coordinate axes (say X-axis):
If we assume that the rotation axis is parallel to X-axis then we need to first translate the axis such that it coincides with X-axis, and then perform standard rotation about X-axis, followed by inverse translation as shown below.
General 3D rotation about any axis randomly oriented in space:
- Translate the axis so the rotation axis passes through the origin
- Rotate the axis so that the axis coincides with one of the coordinate (x, y, or z) axes
- Perform the specified rotation about the selected coordinate axis
- Apply the inverse rotations to bring the coordinate axis back to its original orientation
- Apply the inverse translation to bring the rotation axis back to its original spatial location
This complex rotation can be represented in notation form as
Scaling in 3D:
It is same as that in 2D, except for the additional scaling factor Sz along the z-axis
Reflection in 3D:
Reflection in 3D involves a plane of reflection with respect to which objects are reflected (unlike 2D reflection which involves axis of reflection). We can consider the standard reflection planes the XY plane, whose equation is Z=0, the YZ plane whose equation is X=0 and the XZ plane, whose equation is Y=0. When we perform reflection with respect to a standard plane say the XY plane, the x and y coordinates remain the same and the z-coordinate gets flipped.
The above matrix can be represented in notation form as
Where RFz is reflection with respect to Z=0 plane (XY plane). We can write similar equations for reflections with respect to other standard planes.
Shear in 3D:
Shear in 3D, produces shapes that are deformed, but unlike 2D shear, 3D shear affects planes, i.e., an object gets sheared along a shearing plane. Z-axis shear, represented as SHz is given by
Parameters, a and b in the matrix shown above, can be assigned any real values. The effect of this transformation is to shear X and Y values by an amount proportional to the z-value i.e., to shear planes of constant Z.
Summary:
- Learnt coordinate system conventions.
- Learnt basic 3D Transformations including Translation, Rotation and Scaling, Rotation about an arbitrary axis.
- Other transformations including Reflection, shear.
you can view video on 3D Transformations |