tesseract++ 0.0.1
N-dimensional tensor library for embedded systems
Loading...
Searching...
No Matches
skew_symmetric.h
Go to the documentation of this file.
1#ifndef FUSED_ALGORITHMS_SKEW_SYMMETRIC_H
2#define FUSED_ALGORITHMS_SKEW_SYMMETRIC_H
3
4#include "config.h"
7#include "math/math_utils.h" // math::sqrt, math::sin, math::cos
8#include "algorithms/operations/norms.h" // norm2
9
54namespace matrix_algorithms
55{
56
64 template <typename T>
66 {
68
69 S(0, 1) = -v(2);
70 S(0, 2) = v(1);
71 S(1, 0) = v(2);
72 S(1, 2) = -v(0);
73 S(2, 0) = -v(1);
74 S(2, 1) = v(0);
75
76 return S;
77 }
78
89 template <typename T>
91 {
92 static_assert(is_floating_point_v<T>,
93 "rodrigues requires a floating-point scalar type");
94
96 I.setIdentity();
97
98 // ‖ω‖
99 T norm = norm2(omega);
100
101 // θ = t · ‖ω‖
102 T theta = t * norm;
103
104 if (theta <= T(PRECISION_TOLERANCE))
105 {
106 // Small angle: R ≈ I + t · [ω]×
107 auto S = skew_symmetric(omega);
108
109 FusedMatrix<T, 3, 3> R(T(0));
110 R = I;
111 R(0, 1) += t * S(0, 1);
112 R(0, 2) += t * S(0, 2);
113 R(1, 0) += t * S(1, 0);
114 R(1, 2) += t * S(1, 2);
115 R(2, 0) += t * S(2, 0);
116 R(2, 1) += t * S(2, 1);
117
118 return R;
119 }
120
121 // [ω̂]× where ω̂ = ω/‖ω‖ (unit axis)
122 FusedVector<T, 3> omega_hat(T(0));
123 omega_hat(0) = omega(0) / norm;
124 omega_hat(1) = omega(1) / norm;
125 omega_hat(2) = omega(2) / norm;
126
127 auto K = skew_symmetric(omega_hat);
128
129 // K² = [ω̂]ײ
130 auto K2 = FusedMatrix<T, 3, 3>::matmul(K, K);
131
132 // R = I + sin(θ)·K + (1 − cos(θ))·K²
133 T s = math::sin(theta);
134 T c = math::cos(theta);
135
136 FusedMatrix<T, 3, 3> R(T(0));
137
138 for (my_size_t i = 0; i < 3; ++i)
139 {
140 for (my_size_t j = 0; j < 3; ++j)
141 {
142 R(i, j) = I(i, j) + s * K(i, j) + (T(1) - c) * K2(i, j);
143 }
144 }
145
146 return R;
147 }
148
149} // namespace matrix_algorithms
150
151#endif // FUSED_ALGORITHMS_SKEW_SYMMETRIC_H
Definition fused_matrix.h:12
FusedMatrix & setIdentity(void)
Definition fused_matrix.h:234
static FusedMatrix< T, Rows, Cols > matmul(const BaseExpr< LeftExpr > &mat1, const BaseExpr< RightExpr > &mat2)
Definition fused_matrix.h:255
Definition fused_vector.h:9
Global configuration for the tesseract tensor library.
#define my_size_t
Size/index type used throughout the library.
Definition config.h:126
#define PRECISION_TOLERANCE
Tolerance for floating-point comparisons (e.g. symmetry checks, Cholesky).
Definition config.h:117
T cos(T x)
Definition cos.h:7
constexpr T sin(T x) noexcept
Compute the sine of a floating-point value (radians).
Definition math_utils.h:70
Definition cholesky.h:52
FusedMatrix< T, 3, 3 > skew_symmetric(const FusedVector< T, 3 > &v)
Construct the 3×3 skew-symmetric matrix [v]× from a 3-vector.
Definition skew_symmetric.h:65
T norm2(const FusedVector< T, N > &v)
Compute the Euclidean (2-norm) of a vector: √(Σ vᵢ²).
Definition norms.h:68
FusedMatrix< T, 3, 3 > rodrigues(const FusedVector< T, 3 > &omega, T t=T(1))
Compute the rotation matrix R = exp(t · [ω]×) via Rodrigues formula.
Definition skew_symmetric.h:90
Matrix and vector norms.