# Implicit Representation of the Orientation: a Rotation Matrix

In the previous lesson, we became familiar with the concept of the configuration for the robots, and we saw that the configuration of a robot could be expressed by the pair (R,p) in which R is the rotation matrix that implicitly represents the orientation of the body frame with respect to the reference frame and p is the position of the origin of the body frame relative to the space frame.

In this lesson, we will focus on the orientation, and we will see that we can implicitly represent the orientation using powerful tools named rotation matrices, and we will understand everything about rotation matrices and their properties and various uses.

This lesson is part of the series of lessons on foundations necessary to express robot motions. For the full comprehension of the Fundamentals of Robot Motions and the necessary tools to represent the configurations, velocities, and forces causing the motion, please read the following lessons (note that more lessons will be added in the future):

https://www.mecharithm.com/category/fundamentals-of-robotics/fundamentals-of-robot-motions/

Also, reading some lessons from the base lessons of the Fundamentals of Robotics course are deemed invaluable.

## Introduction to Rotation Matrices

In the lesson about the degrees of freedom of a mechanism, we learned that we need three parameters to explicitly represent a rigid body’s orientation (rotations around the x, y, and z axes). One implicit way to represent the orientation of a rigid body is using 3×3 rotation matrices (note that this is one of the applications of the rotation matrix) to express the orientation of the body frame relative to the base frame. With the 9-dimensional space of the 3×3 rotation matrices subject to 6 constraints, we can implicitly represent the 3-dimensional space of orientations. In other words, of these 9 parameters, only 3 can be chosen independently. The reason that we opt for implicit representation is to take advantage of the algebraic calculations on matrices.

In the previous lesson, we saw the rotation matrix describing the orientation of a toy car on the plane. Now let’s derive a similar representation for the orientation of a robot in space. Suppose a robot in space as shown in the figure below where {b} is the stationary body frame instantaneously attached to the moving body and {s} is the space or reference frame:

The rotation matrix R can be defined as a representation of the body frame unit axes expressed in the base frame as:

We saw before that the dot represents the dot product between the two vectors, and since the coordinate axes are of unit lengths, it represents the cosine of the angle between the two vectors.

The nine numbers in this rotation matrix is subject to six constraints (so that we have 3 degrees of freedom). The constraints are:

- The unit norm constraint says that the columns of the rotation matrix R are unit vectors (because they are coordinate axes):

Note that ||.|| represents the norm of a vector.

- The orthogonality condition says that the column vectors of the rotation matrix are orthogonal to each other since they are coordinate axes, and thus the dot/inner product of any two column vectors is zero:

We can write these six constraints in the compact form as:

Where R^{T} is the transpose of R and I is the identity matrix.

As we discussed in the preliminaries lesson, all frames in robotics are taken to be right-handed meaning that the cross product of the x and y axes is the z-axis (and so on):

And not left handed:

But the six constraints that we just discussed do not account for this since:

If we take the right-handed coordinate system, then the determinant of R will be calculated as:

This result comes from the fact that our frames are right handed and thus:

Also, we know that for a 3×3 matrix A defined by its columns as:

The determinant of A can be found by the following formula:

So, we can conclude that for a right-handed frame, det R = 1, whereas the 6 constraints do not account for this, and thus we need to have another constraint that determinant of R is equal to 1 because our frames are right-handed. This constraint obviously does not reduce the degrees of freedom, and the number of independent constraints is still six.

### Special Orthogonal Group SO(3)

By definition, the group of rotation matrices is called the special orthogonal group SO(3), which is a set of all 3×3 real matrices R that satisfy R^{T} R = I and det R = 1. Elements of SO(3) are called spatial orientations. More generally, the space of rotation matrices in ℝ^{n×n} can be defined as:

A subgroup of SO(3) is the set of 2×2 rotation matrices called the special orthogonal group SO(2) that consists of all 2×2 real matrices R satisfying R^{T} R = I, and det R = 1. As we saw before in the planar example in the previous lesson, the rotation matrix representing the planar orientations which is an element of SO(2), can be expressed as:

Where,

## Properties of Rotation Matrices

Sets of rotation matrices SO(2) and SO(3) are groups and thus have properties of a mathematical group. In general, the SO(n) groups are called Lie groups. A mathematical group has a set of elements and an operation on two elements (this operation is matrix multiplication for SO(n)) such that for all R_{1} and R_{2} in the group SO(n):

- The group has closure property and this means that the multiplication of the two matrices in the group also belongs to the group:

To show this for the SO(3), suppose that R_{1} and R_{2} belong to SO(3), then we can write:

And thus the product of two rotation matrices is also a rotation matrix.

- The group has associativity property:

Note that the multiplication of rotation matrices is associative but generally not commutative:

Rotations only commute for the special case of rotation matrices in SO(2). To show this suppose that R, and M are two rotation matrices in SO(2):

Where because of the case for planar rotations that we saw in the previous lesson, we have:

Thus with an easy calculation, we can see that RM = MR, and thus for the special case of the planar rotations, multiplication of the rotation matrices commute. For example, if you rotate a coordinate frame attached instantaneously to a body confined to a plane first by 45 degrees and then by 30 degrees, the result is the same as when you rotate it first by 30 degrees and then by 45 degrees.

- There exists an identity element in SO(n) such that RI = IR = R.

Note that the identity matrix I can be viewed as the trivial example of a rotation matrix. Imagine this by visualizing the first frame aligned with the reference frame.

- There exists an inverse element R
^{-1}in SO(n) such that RR^{-1}= R^{-1}R = I.

For SO(3), we can say that the inverse of a rotation matrix R in SO(3) is also a rotation matrix, and R^{-1}= R^{T} (this is obvious from the fact that R^{T}R = I). To check this, we should check that R^{-1} satisfies the two properties of the rotation matrices:

\begin{cases} (R^{-1})^T R^{-1} = (R^{T})^T R^{T} = RR^{T} = I \\ det \, R^{-1} = det \, R^{T} = det \, R = 1 \end{cases}

And thus the inverse of R is also a rotation matrix. Note that RR^{T} = I because:

Also, note that when a rotation matrix is applied to a vector to rotate it, this does not change the length of the vector. In other words:

Proof:

Where ||.|| is the norm of the vector.

## Uses of Rotation Matrices

A rotation matrix can be used for three different purposes that we will discuss in the coming paragraphs.

### Implicit Representation of the Orientation

As we discussed earlier, a rotation matrix can be used to implicitly represent an orientation; in other words, it can be used to represent the orientation of the body frame relative to the base frame.

In order to represent the configuration of a rigid body, as we saw in the previous lesson, we need to represent the position and orientation of the rigid body with respect to a base frame. One way to implicitly represent the orientation of a frame relative to the base frame is using rotation matrices. In order to show this, we use an example that is adapted from the reference book “Modern Robotics: Mechanics, Planning, and Control” by Kevin Lynch and Frank Park. Suppose we have three reference frames {s}, {b}, and {c} that represent the same space with different orientations:

Coordinate frame {b} can be archived by rotating the {s} frame by 90 degrees about the {s} frame’s z-axis, and frame {c} is achieved by rotating the {b} frame by -90 degrees about the {b} frame’s y axis. Watch the short demonstration below to understand how these coordinate frames are achieved:

As we discussed, a rotation matrix can be used to represent the orientation of one frame relative to the base frame. Now, let’s see the rotation matrices representing the orientations of the {b} and {c} coordinate frames relative to the {s} frame. By writing the coordinate axes of the {b} and {c} frames in the {s} frame we can get:

R_{sb} and R_{sc} represent the orientations of the {b} and {c} frames relative to the {s} frame, respectively.

It’s easy to note that the coordinate axes of the {s} frame in the for example {c} frame can be achieved by inverting (or transposing in the case of rotation matrices) the rotation matrix representing the orientation of the {c} frame relative to the {s} frame:

Note that because of the properties of a rotation matrix, the inverse of a rotation matrix is equal to the transpose of a rotation matrix.

Also, note that the point p has the same location in the space but have different representations depending on the choice of the coordinate frame:

### Changing the Reference Frame of a Vector or a Frame (Rotation Matrix is an Operator)

One of the applications of a rotation matrix is to change the reference frame of a vector or a frame. Here, a rotation matrix is an operator that acts on a vector or a frame to change its reference frame. For example, to show the change of frame of reference for a coordinate frame, suppose that we have the rotation matrix representing the orientation of the {c} frame relative to the {b} frame as (frames are defined above):

The goal is to express the {c} frame in {s} frame coordinates instead of the {b} coordinates. To achieve this goal, we can use the rotation matrix R_{sb} as a math operator that changes the reference frame from {b} to {s} and then pre-multiply R_{bc} by this math operator to get R_{sc}:

By pre-multiplying R_{bc} by R_{sb}, we change the representation of the {c} frame from the {b} frame to the {s} frame. Note that the subscript cancellation rule says that the second frame of the first subscript should be the same as the first frame of the second subscript (both are {b}).

A rotation matrix can also serve as an operator to change the frame of reference for a vector. For instance, suppose that we have p_{b} that represents the position of point p expressed in {b} frame coordinates as the following figure:

We want to express p in {s} frame coordinates. We can do this by pre-multiplying p_{b} by R_{sb} to get the point coordinates in the {s} frame:

Note that subscript cancellation rule works here too.

### Rotating a Vector or a Frame (Rotation matrix is an operator)

Another application (and the final one) of a rotation matrix is to rotate a vector or a frame. Here again, a rotation matrix is an operator that acts on a vector or a frame to rotate it.

Consider the three coordinate axes {s}, {b}, and {c} described as above. As we saw before, {b} is achieved by rotating the {s} frame by 90 degrees about the z-axis of the {s} frame. R_{sb} here can also serve as an operator that can rotate a vector or a frame by 90 degrees about the z-axis:

Pre-multiplying p_{s} by R_{sb} does not follow the subscript cancellation rule and thus the rotation matrix does not serve as the operator to change the reference frame but rather it acts as an operator to rotate the vector p_{s} by 90 degrees about the z-axis of the {s} frame:

This vector represents the rotated p_{s} vector by 90 degrees about the z-axis of the {s} frame. The vector is rotated but it is still represented in the original frame {s}:

Note that to rotate a vector v, there is only one frame involved and that is the frame in which v is represented and the axis of rotation is interpreted in this frame:

v’ is the rotated vector v in the same frame.

A rotation matrix can also be used to rotate a frame. Suppose that we have the rotation operator R that can rotate a frame by 90 degrees about the z-axis:

Now let’s see what happens to a frame if we pre-multiply or post-multiply it by this rotation operator. Note that the choice of the z-axis to be from which frame depends on the pre-multiplication or post-multiplication of the rotation matrix. Now suppose the {s} and {c} coordinate frames that we had before:

The {c} frame orientation will be different depending on if the rotation matrix representing its orientation with respect to the base frame (R_{sc}) is pre-multiplied or post-multiplied by the rotation operator R.

If we pre-multiply by the rotation operator R defined above, then the rotation axis is the z-axis of the first subscript, which is s so that the rotation is about the z-axis of the {s} coordinate frame:

If we post-multiply by the rotation operator R defined above, then the rotation axis is the z-axis of the second subscript, which is c so that the rotation is about the z-axis of the {c} coordinate frame:

Generally speaking, if R_{sb} represents the orientation of some frame {b} w.r.t the base frame {s}, and if we want to rotate {b} by θ about a unit axis ῶ, in other words, by a rotation operator R = Rot(ῶ,θ)), then:

- Coordinate frame {b’} is the new frame after a rotation by θ about ῶ
_{s}= ῶ, and this means that the rotation axis is considered to be in the fixed frame {s}:

- Coordinate frame {b”} is the new frame after a rotation by θ about ῶ
_{b}= ῶ, and this means that the rotation axis is in the body frame {b}:

Where

And ῶ can be either in {s} frame or {b} frame based on pre-multiplying by R or post-multiplying by R. As we just saw, if we pre-multiply by R, then the rotation is about an axis ῶ in the fixed frame, and if we post-multiply by R, then the rotation is about ῶ in the body frame. The multiplication of ῶ and θ is a 3-vector representation of the orientation that is called exponential coordinates of orientation that is an explicit representation and will be discussed in the next lesson.

#### Rotation Operators about the x, y, and z Axes

Now let’s find general forms of rotation operators representing the rotations about the x, y, and z axes by θ degrees.

The rotation operator representing the rotation about the x axis by θ degrees can be visualized as:

Using the figure below:

We can find the rotation operator representing the rotation about the x-axis as:

With the same approach rotation operators representing the rotations about the y-axis and the z-axis can be found as:

and

Generally, the rotation about an arbitrary unit axis ῶ

by θ can be represented by a rotation operator as:

Where

We will see how to derive this rotation matrix in the next lesson when talking about the exponential coordinates of rotation. For now, you can verify that it is correct by assuming ῶ = (1,0,0), (0,1,0), and (0,0,1) for rotations around x, y, and z, respectively, and get rotation matrices that we calculated above.

Visualize this rotation as the following figure:

Note that any R ∈ SO(3) can be obtained by rotating from the identity matrix by some θ about some ῶ. Also, note that:

In other words, rotation about -ῶ by -θ is the same as the rotation about ῶ by θ. These are topics of the next video.

## Demonstration: the Representation of the Orientation of the Elements in the Robot’s Workspace

Suppose that a camera and a gripper are attached to the end-effector of the industrial arm. The camera is used to observe the workpiece and position the end-effector in the right position, and the gripper is used to grip the workpiece. The overall system can be depicted in the figure below:

Four frames are attached to different elements in the robot’s workspace, as shown above. {a} is the frame coincident with the space frame {s}, {b} is the gripper frame, {c} is the camera frame, and {d} is the workpiece frame.

The orientation of the workpiece frame relative to the base frame can be expressed by the rotation matrix R_{ad} as:

This means that the two frames have the same orientation.

The orientation of the workpiece frame relative to the camera frame can be calculated as follows:

Now suppose we have the rotation matrix representing the orientation of the camera frame relative to the gripper frame as:

To calculate the orientation of the gripper frame relative to the space frame R_{ab}, we can use the second application of the rotation matrix to act as an operator to change the reference frame of a frame as:

Note that we used the inverse of a rotation matrix equals its transpose and the subscript cancellation rule to calculate the result.

## Demonstration: Successive Rotations of a Point about the Coordinate Axes of the Base Frame

Suppose p is a point in space with coordinates relative to the space frame as p_{s} = (5,-7,10). In the preliminaries lesson, we saw that we could represent a point in space with a vector. The point p and the corresponding vector representation can be visualized as the following figure:

Now suppose that p is rotated about the fixed-frame x-axis by 30^{o}, then about the fixed frame y-axis by 135^{o}, and finally about the fixed frame z-axis by -120^{o}. The rotation matrix that rotated p to the new location can be expressed as (note the order in which the rotations are written):

These rotations can easily be calculated using the rotation operators about the coordinate axes provided above.

Then the coordinates of the rotated point can be calculated as:

The rotated point can be visualized as:

In the next lesson, we will talk about Exponential Coordinate Representation of Rotation which is an explicit way to represent the orientation.

The video version of the current lesson can be watched at the link below:

References:

📘 Textbooks:

Modern Robotics: Mechanics, Planning, and Control by Frank Park and Kevin Lynch

A Mathematical Introduction to Robotic Manipulation by Murray, Lee, and Sastry

📃 Articles:

- Cao, C.T., Do, V.P. and Lee, B.R., 2019. A novel indirect calibration approach for robot positioning error compensation based on neural network and hand-eye vision.
*Applied Sciences*,*9*(9), p.1940.

✍️ Logo design by Minro Art Group