Template Class SO2
Defined in File so2.hpp
-
template<typename K>
class SO2 Class representing 2D rotations using the SO(2) group.
This class represents rotations in 2D space as elements of the special orthogonal group SO(2). Internally, rotations are stored as normalized direction vectors (cos, sin) to avoid trigonometric function calls during composition and transformation operations.
- Template Parameters
K – Scalar type (typically float or double).
Public Types
-
using Scalar = K
Public Functions
-
inline SO2()
Default constructor creates an undefined rotation.
NoteUse identity() to create the identity rotation.
-
inline K cos() const
Get the cosine of the rotation angle.
NoteThis is a simple getter and does not call trigonometric functions.
- Returns
Cosine of the rotation angle.
-
inline K sin() const
Get the sine of the rotation angle.
NoteThis is a simple getter and does not call trigonometric functions.
- Returns
Sine of the rotation angle.
-
inline const Vector2<K> &as_direction() const
Get the cos and sin of the rotation angle as a direction vector.
- Returns
Direction vector (cos, sin).
-
inline K angle() const
Get the rotation angle in range [-π, π].
NoteThis uses a call to a trigonometric function.
- Returns
Rotation angle in radians.
-
inline Matrix2<K> matrix() const
Get the 2×2 rotation matrix representation.
- Returns
2×2 rotation matrix.
-
inline SO2 inverse() const
Get the inverse rotation.
- Returns
Inverse rotation.
-
template<typename S, typename std::enable_if_t<!std::is_same<S, K>::value, int> = 0>
inline SO2<S> cast() const Cast to a different scalar type.
- Template Parameters
S – Target scalar type.
- Returns
Rotation cast to the target type.
-
template<typename S, typename std::enable_if_t<std::is_same<S, K>::value, int> = 0>
inline const SO2 &cast() const Cast to the same scalar type (no-op).
- Template Parameters
S – Target scalar type (same as K).
- Returns
Reference to this rotation.
Public Static Functions
-
static inline SO2 identity()
Create the identity rotation.
- Returns
Identity rotation (no rotation).
-
static inline SO2 from_angle(K angle)
Create rotation from an angle.
NoteThis uses calls to trigonometric functions.
- Parameters
angle – Rotation angle in radians.
- Returns
Rotation representing the given angle.
-
static inline SO2 from_direction(const Vector2<K> &direction)
Create rotation from a not necessarily normalized direction vector.
- Parameters
direction – Direction vector (will be normalized internally).
- Returns
Rotation aligned with the given direction.
-
static inline SO2 from_direction(K dx, K dy)
Create rotation from direction components.
- Parameters
dx – X component of direction vector.
dy – Y component of direction vector.
- Returns
Rotation aligned with the given direction.
-
static inline SO2 from_normalized(const Vector2<K> &cos_sin)
Create rotation from a normalized cos/sin direction vector.
- Parameters
cos_sin – Normalized direction vector (cos, sin).
- Returns
Rotation represented by the given cos/sin values.
-
static inline SO2 from_normalized(K cos_angle, K sin_angle)
Create rotation from normalized cos and sin values.
- Parameters
cos_angle – Cosine of the rotation angle.
sin_angle – Sine of the rotation angle.
- Returns
Rotation represented by the given cos/sin values.
Public Static Attributes
-
static constexpr int kDimension = 2
Friends
-
inline friend SO2 operator*(const SO2 &lhs, const SO2 &rhs)
Compose two rotations.
- Parameters
lhs – Left rotation.
rhs – Right rotation.
- Returns
Composed rotation lhs * rhs.
-
inline friend Vector2<K> operator*(const SO2 &lhs, const Vector2<K> &vec)
Rotate a 2D vector.
- Parameters
lhs – Rotation to apply.
vec – Vector to rotate.
- Returns
Rotated vector.