Skip to content

Commit 5a88e81

Browse files
feat(math): elementary rotations about the coordinate axes (#384)
RotationX, RotationY and RotationZ build the rotation about one coordinate axis from one sine and one cosine, without the general axis-angle products. They compose fixed-axis roll-pitch-yaw orientations R_z(yaw) R_y(pitch) R_x(roll) for mounting and tool frames, which consumers currently write by hand. Claude-Session: https://claude.ai/code/session_014WUWh8Fw5EhcfvNuXz3jjU Co-authored-by: Claude <noreply@anthropic.com>
1 parent ef08d4d commit 5a88e81

4 files changed

Lines changed: 69 additions & 0 deletions

File tree

‎doc/math/SE3Transform.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ $$T_1 T_2 = (R_1 R_2,\; R_1 p_2 + p_1), \qquad T^{-1} = (R^T,\; -R^T p), \qquad
1818

1919
The composition applies $T_2$ first. The inverse follows from $R^{-1} = R^T$. A free direction is only rotated, $x \mapsto R x$; the translation is ignored.
2020

21+
### Elementary Rotations
22+
23+
Rotations about the coordinate axes have closed forms that need one sine and one cosine:
24+
25+
$$R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 \\ 0 & c & -s \\ 0 & s & c \end{bmatrix}, \quad R_y(\theta) = \begin{bmatrix} c & 0 & s \\ 0 & 1 & 0 \\ -s & 0 & c \end{bmatrix}, \quad R_z(\theta) = \begin{bmatrix} c & -s & 0 \\ s & c & 0 \\ 0 & 0 & 1 \end{bmatrix}$$
26+
27+
with $c = \cos\theta$, $s = \sin\theta$. They are the axis–angle rotation for a unit coordinate axis, without its general products, and compose the fixed-axis roll–pitch–yaw orientation $R_z(\psi)\,R_y(\theta)\,R_x(\phi)$ used for mounting and tool frames.
28+
2129
### Ordering Convention (normative)
2230

2331
All 6-vectors are ordered **linear part first**: twists $V = (v;\, \omega)$ and wrenches $W = (f;\, n)$. This matches a geometric Jacobian with linear rows first and the tangent ordering of Sophus and manif. Lynch & Park and Murray et al. use $(\omega;\, v)$; the two conventions differ by a block permutation, so any formula from those texts converts by swapping the blocks (for the adjoint below, the rotation blocks stay on the diagonal and the $[p]_\times R$ block moves to the lower left).

‎numerical/math/Geometry3D.hpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ namespace math
5353
};
5454
}
5555

56+
template<typename T>
57+
ALWAYS_INLINE_HOT Matrix3<T> RotationX(T angle)
58+
{
59+
const T c{ math::Cos(angle) };
60+
const T s{ math::Sin(angle) };
61+
return Matrix3<T>{ { T(1), T(0), T(0) }, { T(0), c, -s }, { T(0), s, c } };
62+
}
63+
64+
template<typename T>
65+
ALWAYS_INLINE_HOT Matrix3<T> RotationY(T angle)
66+
{
67+
const T c{ math::Cos(angle) };
68+
const T s{ math::Sin(angle) };
69+
return Matrix3<T>{ { c, T(0), s }, { T(0), T(1), T(0) }, { -s, T(0), c } };
70+
}
71+
72+
template<typename T>
73+
ALWAYS_INLINE_HOT Matrix3<T> RotationZ(T angle)
74+
{
75+
const T c{ math::Cos(angle) };
76+
const T s{ math::Sin(angle) };
77+
return Matrix3<T>{ { c, -s, T(0) }, { s, c, T(0) }, { T(0), T(0), T(1) } };
78+
}
79+
5680
template<typename T>
5781
ALWAYS_INLINE_HOT Matrix3<T> ScaledIdentity(T value)
5882
{

‎numerical/math/test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ target_sources(numerical.math_test PRIVATE
2020
TestCubicSpline.cpp
2121
TestCordic.cpp
2222
TestFastTrigonometry.cpp
23+
TestGeometry3D.cpp
2324
TestGivensRotation.cpp
2425
TestHouseholderTransform.cpp
2526
TestLinearTimeInvariant.cpp
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "numerical/math/Geometry3D.hpp"
2+
#include "numerical/math/Tolerance.hpp"
3+
#include <gtest/gtest.h>
4+
#include <numbers>
5+
6+
namespace
7+
{
8+
class Geometry3DTest : public ::testing::Test
9+
{
10+
protected:
11+
static void ExpectNear(const math::Matrix3<float>& actual, const math::Matrix3<float>& expected)
12+
{
13+
for (std::size_t i = 0; i < 3; ++i)
14+
for (std::size_t j = 0; j < 3; ++j)
15+
EXPECT_NEAR(actual.at(i, j), expected.at(i, j), math::Tolerance<float>());
16+
}
17+
18+
float angle{ 0.7f };
19+
};
20+
}
21+
22+
TEST_F(Geometry3DTest, ElementaryRotationsMatchTheRotationAboutTheirAxis)
23+
{
24+
ExpectNear(math::RotationX(angle), math::RotationAboutAxis(math::Vector3<float>{ 1.0f, 0.0f, 0.0f }, angle));
25+
ExpectNear(math::RotationY(angle), math::RotationAboutAxis(math::Vector3<float>{ 0.0f, 1.0f, 0.0f }, angle));
26+
ExpectNear(math::RotationZ(angle), math::RotationAboutAxis(math::Vector3<float>{ 0.0f, 0.0f, 1.0f }, angle));
27+
}
28+
29+
TEST_F(Geometry3DTest, RotationZTurnsTheXAxisTowardsTheYAxis)
30+
{
31+
const auto turned = math::RotationZ(std::numbers::pi_v<float> / 2.0f) * math::Vector3<float>{ 1.0f, 0.0f, 0.0f };
32+
33+
EXPECT_NEAR(turned.at(0, 0), 0.0f, math::Tolerance<float>());
34+
EXPECT_NEAR(turned.at(1, 0), 1.0f, math::Tolerance<float>());
35+
EXPECT_NEAR(turned.at(2, 0), 0.0f, math::Tolerance<float>());
36+
}

0 commit comments

Comments
 (0)