Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

πŸ““ Robotics/Computer Vision Notes: Coordinate Transformations

πŸ““ Robotics/Computer Vision Notes: Coordinate TransformationsΒΆ

This notebook translates handwritten notes on coordinate transformations, focusing on rotation, translation, and properties of rotation matrices, often used in robotics and computer vision (e.g., in systems utilizing ROS 2 and Aruco markers).

Setup and Data Snippet (ROS 2 Aruco Detection)ΒΆ

The notes include a snippet of data from an Aruco detection topic in a ROS 2 environment, which provides the pose (position and orientation) of a detected marker.

The marker’s pose is given relative to a frame identified as /v41_frame.

Rigid Body Transformation ConceptsΒΆ

A Rigid body is defined as a set of points where the distance between any two points remains constant after a transformation.

The transformation involves a Rotation (RR) and a Translation (tt). All points in the rigid body rotate and translate by the same amount.

The transformation of a point pβ€ΎJ\underline{p}_J in the source frame JJ to a point pβ€ΎW\underline{p}_W in the destination frame WW is given by:

pβ€ΎW=WRJpβ€ΎJ+Wtβ€ΎJ(1)\underline{p}_W = {}^W R_J \underline{p}_J + {}^W \underline{t}_J \tag{1}
  • pβ€ΎW\underline{p}_W: Point in the World/Destination frame (WW)

  • pβ€ΎJ\underline{p}_J: Point in the Source frame (JJ)

  • WRJ{}^W R_J: Rotation matrix from frame JJ to WW

  • Wtβ€ΎJ{}^W \underline{t}_J: Translation vector from frame JJ to WW

In 2D, this equation expands to:

(xWyW)=(r11r12r21r22)(xJyJ)+(t1t2)\begin{pmatrix} x_W \\ y_W \end{pmatrix} = \begin{pmatrix} r_{11} & r_{12} \\ r_{21} & r_{22} \end{pmatrix} \begin{pmatrix} x_J \\ y_J \end{pmatrix} + \begin{pmatrix} t_1 \\ t_2 \end{pmatrix}

2D Rotation DerivationΒΆ

The notes derive the transformation for a 2D rotation of a point pβ€Ύ=(xy)\underline{p} = \begin{pmatrix} x \\ y \end{pmatrix} rotated by an angle ΞΈ\theta to a new point pβ€Ύβ€²=(xβ€²yβ€²)\underline{p}' = \begin{pmatrix} x' \\ y' \end{pmatrix}.

Given:

  • x=rcos⁑αx = r \cos\alpha

  • y=rsin⁑αy = r \sin\alpha

  • xβ€²=rcos⁑(ΞΈ+Ξ±)x' = r \cos(\theta+\alpha)

  • yβ€²=rsin⁑(ΞΈ+Ξ±)y' = r \sin(\theta+\alpha)

Using the angle addition formulas (cos⁑(A+B)=cos⁑Acos⁑Bβˆ’sin⁑Asin⁑B\cos(A+B) = \cos A \cos B - \sin A \sin B and sin⁑(A+B)=sin⁑Acos⁑B+cos⁑Asin⁑B\sin(A+B) = \sin A \cos B + \cos A \sin B):

xβ€²=rcos⁑θcosβ‘Ξ±βˆ’rsin⁑θsin⁑αx' = r \cos\theta \cos\alpha - r \sin\theta \sin\alpha

Substituting xx and yy:

xβ€²=xcosβ‘ΞΈβˆ’ysin⁑θx' = x \cos\theta - y \sin\theta
yβ€²=rsin⁑θcos⁑α+rcos⁑θsin⁑αy' = r \sin\theta \cos\alpha + r \cos\theta \sin\alpha

Substituting xx and yy:

yβ€²=xsin⁑θ+ycos⁑θy' = x \sin\theta + y \cos\theta

In matrix form, the 2D Rotation Matrix R(ΞΈ)R(\theta) is:

pβ€Ύβ€²=R(ΞΈ)pβ€Ύ\underline{p}' = R(\theta)\underline{p}
(xβ€²yβ€²)=(cosβ‘ΞΈβˆ’sin⁑θsin⁑θcos⁑θ)(xy)\begin{pmatrix} x' \\ y' \end{pmatrix} = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix}

Homogeneous Coordinates and Transformation MatrixΒΆ

To represent rotation and translation (Equation 1) as a single matrix multiplication, homogeneous coordinates are used. A 2D point pβ€Ύ=(xy)\underline{p} = \begin{pmatrix} x \\ y \end{pmatrix} is extended to (xy1)\begin{pmatrix} x \\ y \\ 1 \end{pmatrix}.

The Transformation Matrix TT in homogeneous coordinates for a transformation from JJ to WW is:

WTJ=(WRJWtβ€ΎJ0β€ΎT1){}^W T_J = \begin{pmatrix} {}^W R_J & {}^W \underline{t}_J \\ \underline{0}^T & 1 \end{pmatrix}

Where 0β€ΎT\underline{0}^T is a row vector of zeros (e.g., (00)\begin{pmatrix} 0 & 0 \end{pmatrix} for 2D).

The transformation becomes:

(pβ€ΎW1)=WTJ(pβ€ΎJ1)\begin{pmatrix} \underline{p}_W \\ 1 \end{pmatrix} = {}^W T_J \begin{pmatrix} \underline{p}_J \\ 1 \end{pmatrix}

Properties of a Rotation MatrixΒΆ

A Rotation Matrix (RR) is a type of orthonormal matrix. An orthonormal matrix UU has columns (or rows) that are orthonormal, meaning:

  • uβ€ΎiTuβ€Ύi=1\underline{u}_i^T \underline{u}_i = 1 (Unit length)

  • uβ€ΎiTuβ€Ύj=0\underline{u}_i^T \underline{u}_j = 0 for iβ‰ ji \ne j (Orthogonal)

1. Inverse and TransposeΒΆ

For any orthonormal matrix UU, its inverse is equal to its transpose:

Uβˆ’1=UTU^{-1} = U^T

Therefore, for a rotation matrix RR:

Rβˆ’1=RTR^{-1} = R^T

This property is geometrically intuitive: transforming a point back from Pβ€²P' to PP (reversing a rotation by ΞΈ\theta) is equivalent to a rotation by βˆ’ΞΈ-\theta.

Rβˆ’1(ΞΈ)=R(βˆ’ΞΈ)=(cos⁑(βˆ’ΞΈ)βˆ’sin⁑(βˆ’ΞΈ)sin⁑(βˆ’ΞΈ)cos⁑(βˆ’ΞΈ))=(cos⁑θsinβ‘ΞΈβˆ’sin⁑θcos⁑θ)R^{-1}(\theta) = R(-\theta) = \begin{pmatrix} \cos(-\theta) & -\sin(-\theta) \\ \sin(-\theta) & \cos(-\theta) \end{pmatrix} = \begin{pmatrix} \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \end{pmatrix}

Which is RTR^T:

RT=(cos⁑θsinβ‘ΞΈβˆ’sin⁑θcos⁑θ)R^T = \begin{pmatrix} \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \end{pmatrix}

Also, RRT=RTR=IR R^T = R^T R = I (Identity matrix).

2. DeterminantΒΆ

For an orthonormal matrix UU, the determinant must be det⁑(U)∈{βˆ’1,+1}\det(U) \in \{-1, +1\}.

A pure Rotation matrix RR has a determinant of positive one:

det⁑(R)=1\det(R) = 1

For the 2D rotation matrix:

det⁑((cosβ‘ΞΈβˆ’sin⁑θsin⁑θcos⁑θ))=cos⁑2ΞΈβˆ’(βˆ’sin⁑2ΞΈ)=cos⁑2ΞΈ+sin⁑2ΞΈ=1\det\left(\begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}\right) = \cos^2\theta - (-\sin^2\theta) = \cos^2\theta + \sin^2\theta = 1

If an orthonormal matrix has det⁑(U)=βˆ’1\det(U) = -1, it represents a Reflection matrix. Thus, not all orthonormal matrices are rotation matrices.

Inverse TransformationΒΆ

The notes also demonstrate how to find the inverse transformation, JTW=(WTJ)βˆ’1{}^J T_W = ({}^W T_J)^{-1}.

Starting from the point transformation:

pβ€ΎW=WRJpβ€ΎJ+Wtβ€ΎJ\underline{p}_W = {}^W R_J \underline{p}_J + {}^W \underline{t}_J

1. Isolate the rotational term:

pβ€ΎWβˆ’Wtβ€ΎJ=WRJpβ€ΎJ\underline{p}_W - {}^W \underline{t}_J = {}^W R_J \underline{p}_J
  1. Left-multiply by the transpose of the rotation matrix, WRJT{}^W R_J^T, which is the inverse JRW{}^J R_W:

WRJT(pβ€ΎWβˆ’Wtβ€ΎJ)=(WRJTWRJ)pβ€ΎJ{}^W R_J^T (\underline{p}_W - {}^W \underline{t}_J) = \left( {}^W R_J^T {}^W R_J \right) \underline{p}_J

Since WRJTWRJ=I{}^W R_J^T {}^W R_J = I:

WRJTpβ€ΎWβˆ’WRJTWtβ€ΎJ=pβ€ΎJ{}^W R_J^T \underline{p}_W - {}^W R_J^T {}^W \underline{t}_J = \underline{p}_J

This shows the inverse transformation is:

pβ€ΎJ=WRJT⏟JRWpβ€ΎW+(βˆ’WRJTWtβ€ΎJ)⏟Jtβ€ΎW\underline{p}_J = \underbrace{{}^W R_J^T}_{{}^J R_W} \underline{p}_W + \underbrace{\left( -{}^W R_J^T {}^W \underline{t}_J \right)}_{{}^J \underline{t}_W}

The inverse transformation matrix JTW{}^J T_W in homogeneous coordinates is:

JTW=(WRJTβˆ’WRJTWtβ€ΎJ0β€ΎT1)=(JRβ€ΎWJtβ€ΎW0β€ΎT1){}^J T_W = \begin{pmatrix} {}^W R_J^T & -{}^W R_J^T {}^W \underline{t}_J \\ \underline{0}^T & 1 \end{pmatrix} = \begin{pmatrix} {}^J\underline{R}_W & {}^J\underline{t}_W \\ \underline{0}^T & 1 \end{pmatrix}