32 if(!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(z) || !std::isfinite(rot_z)) {
39 frame.
cos_rz = std::cos(rot_z);
40 frame.
sin_rz = std::sin(rot_z);
56 return Vec3{rotated.
x + frame.
x, rotated.
y + frame.
y, rotated.
z + frame.
z};
67 double rotation[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
78 const double cr = std::cos(roll);
79 const double sr = std::sin(roll);
80 const double cp = std::cos(pitch);
81 const double sp = std::sin(pitch);
82 const double cy = std::cos(yaw);
83 const double sy = std::sin(yaw);
87 transform.
rotation[0][1] = cy * sp * sr - sy * cr;
88 transform.
rotation[0][2] = cy * sp * cr + sy * sr;
90 transform.
rotation[1][1] = sy * sp * sr + cy * cr;
91 transform.
rotation[1][2] = sy * sp * cr - cy * sr;
118 for(
int i = 0; i < 3; ++i) {
119 for(
int j = 0; j < 3; ++j) {
136 const double b[3][3],
139 for(
int i = 0; i < 3; ++i) {
140 for(
int j = 0; j < 3; ++j) {
141 out[i][j] = a[i][0] * b[0][j] + a[i][1] * b[1][j] + a[i][2] * b[2][j];
147 const double b[3][3],
152 for(
int i = 0; i < 3; ++i) {
153 for(
int j = 0; j < 3; ++j) {
154 rel[i][j] = a[0][i] * b[0][j] + a[1][i] * b[1][j] + a[2][i] * b[2][j];
157 const double trace = rel[0][0] + rel[1][1] + rel[2][2];
158 double cosine = (trace - 1.0) * 0.5;
159 cosine = cosine > 1.0 ? 1.0 : (cosine < -1.0 ? -1.0 : cosine);
160 angle = std::acos(cosine);
168 const double skew[3] = {rel[2][1] - rel[1][2], rel[0][2] - rel[2][0],
169 rel[1][0] - rel[0][1]};
171 const double scale = 1.0 / (2.0 * std::sin(angle));
172 axis[0] = skew[0] * scale;
173 axis[1] = skew[1] * scale;
174 axis[2] = skew[2] * scale;
176 for(
int i = 0; i < 3; ++i) {
177 double squared = (rel[i][i] - cosine) / (1.0 - cosine);
178 squared = squared < 0.0 ? 0.0 : squared;
179 axis[i] = std::sqrt(squared);
196 const double c = std::cos(angle);
197 const double s = std::sin(angle);
198 const double t = 1.0 - c;
199 const double x =
axis[0];
200 const double y =
axis[1];
201 const double z =
axis[2];
202 out[0][0] = t * x * x + c;
203 out[0][1] = t * x * y - s * z;
204 out[0][2] = t * x * z + s * y;
205 out[1][0] = t * x * y + s * z;
206 out[1][1] = t * y * y + c;
207 out[1][2] = t * y * z - s * x;
208 out[2][0] = t * x * z - s * y;
209 out[2][1] = t * y * z + s * x;
210 out[2][2] = t * z * z + c;
226 const double cos_pitch = std::hypot(rotation[0][0], rotation[1][0]);
227 pitch = std::atan2(-rotation[2][0], cos_pitch);
228 if(cos_pitch < 1e-9) {
230 yaw = std::atan2(-rotation[0][1], rotation[1][1]);
233 roll = std::atan2(rotation[2][1], rotation[2][2]);
234 yaw = std::atan2(rotation[1][0], rotation[0][0]);
241 for(
int i = 0; i < 3; ++i) {
242 for(
int j = 0; j < 3; ++j) {
static constexpr Result success(const T &value)
static constexpr Result failure(ErrorCode error)
Vec3 frame_to_base(const RigidFrame &frame, Vec3 local)
Vec3 transform_rotate(const RigidTransform &transform, Vec3 v)
void rotation_multiply(const double a[3][3], const double b[3][3], double out[3][3])
Vec3 transform_point(const RigidTransform &transform, Vec3 p)
RigidTransform invert(const RigidTransform &transform)
void rodrigues(const double axis[3], double angle, double out[3][3])
bool extract_rpy(const double rotation[3][3], double &roll, double &pitch, double &yaw)
RigidTransform make_rpy_transform(double x, double y, double z, double roll, double pitch, double yaw)
rt::Result< RigidFrame > make_frame(double x, double y, double z, double rot_z)
void relative_axis_angle(const double a[3][3], const double b[3][3], double axis[3], double &angle)
RigidTransform compose(const RigidTransform &a, const RigidTransform &b)
Vec3 frame_rotate(const RigidFrame &frame, Vec3 direction)