wuzp
Wrong Unit? Zero Points! Compile-time checks for units, coordinate systems and points vs. vectors.
Loading...
Searching...
No Matches
PassiveSpatialRotation.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <ostream>
4#include <type_traits>
5#include <utility>
6
10#include "wuzp/core/helpers.hpp"
11#include "wuzp/core/traits.hpp"
16#include "wuzp/trafo/internal/rigid.hpp"
17#include "wuzp/trafo/internal/rotation.hpp"
18#include "wuzp/trafo/internal/rotation_parameterizations.hpp"
19#include "wuzp/trafo/internal/validity.hpp"
20#include "wuzp/trafo/traits.hpp"
21
22namespace wuzp {
23
50template <template <typename, int, int> typename ValuesT_, typename ValueT_, EuclideanCoordinateSystem FromT_,
51 EuclideanCoordinateSystem ToT_, int DimensionV_>
54 : public PassiveTransformation<PassiveSpatialRotation<ValuesT_, ValueT_, FromT_, ToT_, DimensionV_>, FromT_, ToT_> {
55 using ParameterizationsT = internal::RotationParameterizationTypes<ValuesT_, ValueT_>;
56 using RequireParameterizableT = internal::RequireParameterizable<DimensionV_, ValueT_>;
57 using AngleUnitT = typename ParameterizationsT::UnitsT::Angle;
58 using AngularVelocityUnitT = typename ParameterizationsT::UnitsT::AngularVelocity;
59
60 public:
62 using LinearTransformationT = PassiveLinearTransformation<ValuesT_, ValueT_, FromT_, ToT_, DimensionV_,
63 typename AccessUnits<AccessImplementation<ValueT_>>::Dimensionless>;
64 using ValueT = ValueT_;
68
70 using QuaternionT = typename ParameterizationsT::QuaternionT;
72 using QuaternionDerivativeT = typename ParameterizationsT::QuaternionDerivativeT;
74 using AngleT = typename ParameterizationsT::AngleT;
76 using AxisT = typename ParameterizationsT::template AxisT<ToT_>;
78 using AngleAxisT = std::pair<AngleT, AxisT>;
80 using RotationVectorT = typename ParameterizationsT::template RotationVectorT<ToT_>;
83 using EulerAnglesT = typename ParameterizationsT::EulerAnglesT;
85 using EulerAnglesDerivativeT = typename ParameterizationsT::EulerAnglesDerivativeT;
87 using AngularVelocityT = typename ParameterizationsT::template AngularVelocityT<ToT_>;
89 using MatrixDerivativeT = typename ParameterizationsT::MatrixDerivativeT;
90
92 PassiveSpatialRotation() : quantities_{internal::identity<ValuesT>()} {}
93
97 template <typename... Args>
98 requires(sizeof...(Args) > 0 && !CopiesOrMoves<PassiveSpatialRotation, Args...>)
99 explicit PassiveSpatialRotation(Args&&... args) : quantities_{std::forward<Args>(args)...} {
100 internal::checkValidity(*this, "The matrix of a rotation must be orthogonal with determinant 1.");
101 }
102
105 template <typename... Args>
106 static PassiveSpatialRotation makeUnchecked(Args&&... args) {
107 return PassiveSpatialRotation{Unchecked{}, QuantitiesT{std::forward<Args>(args)...}};
108 }
109
114 template <typename... Args>
116 return makeUnchecked(internal::projectToRotation(QuantitiesT{std::forward<Args>(args)...}.getValues()));
117 }
118
120 const QuantitiesT& getQuantities() const { return quantities_; }
121
123 auto inverse() const { return internal::WithFrames<PassiveSpatialRotation, ToT_, FromT_>::type::makeUnchecked(quantities_.transpose()); }
124
127 bool isValid(const ValueT tolerance = ValidityTolerance<ValueT>::value()) const {
128 return internal::isRotation(quantities_.getValues(), tolerance);
129 }
130
133 template <template <typename, int, int> typename ValuesOtherT_, typename ValueOtherT_, typename FromOtherT_, typename ToOtherT_,
134 int DimensionOtherV_>
136 const ValueT precision = Precision<ValueT>::value()) const {
137 static_assert(internal::SameFrames<PassiveSpatialRotation, std::remove_cvref_t<decltype(other)>>::value);
138 return quantities_.isApprox(other.getQuantities(), precision);
139 }
140
141 // The parameterizations of three-dimensional rotations (see "Parameterizations of rotations" in DESIGN.md), which describe the
142 // matrix R of the rotation, like those of the ActiveSpatialRotation with the same matrix. A vector of the tangent space, e.g. an
143 // angular velocity, may be expressed in To or in From; results are expressed in the coordinate system of the template argument,
144 // To by default.
145
150 template <AnyQuantities QuaternionOtherT_>
151 static PassiveSpatialRotation fromQuaternion(const QuaternionOtherT_& quaternion) {
152 static_assert(RequireParameterizableT::value);
153 const auto elements = internal::checkedUnitQuaternion(internal::quaternionElements(QuaternionT{quaternion}),
154 "The quaternion of a rotation must have unit length.");
155 return makeUnchecked(internal::matrixFromQuaternion<ValuesT>(elements));
156 }
157
160 static_assert(RequireParameterizableT::value);
161 return internal::fromElements<QuaternionT>(internal::quaternionFromMatrix(quantities_.getValues()));
162 }
163
168 template <AnyQuantities AngleOtherT_, AnyTensor AxisOtherT_>
169 static PassiveSpatialRotation fromAngleAxis(const AngleOtherT_& angle, const AxisOtherT_& axis) {
170 static_assert(RequireParameterizableT::value);
171 const auto elements = internal::checkedUnitQuaternion(
172 internal::quaternionFromAngleAxis(AngleT{angle}.getValue(), components<typename ParameterizationsT::UnitsT::Dimensionless>(axis)),
173 "The axis of a rotation must have unit length.");
174 return makeUnchecked(internal::matrixFromQuaternion<ValuesT>(elements));
175 }
176
179 static_assert(RequireParameterizableT::value);
180 const auto [angle, axis] = internal::angleAxisFromQuaternion(internal::quaternionFromMatrix(quantities_.getValues()));
181 return {AngleT{angle}, internal::fromElements<AxisT>(axis)};
182 }
183
186 template <AnyTensor RotationVectorOtherT_>
187 static PassiveSpatialRotation fromRotationVector(const RotationVectorOtherT_& rotationVector) {
188 static_assert(RequireParameterizableT::value);
189 return makeUnchecked(internal::matrixFromRotationVector<ValuesT>(components<AngleUnitT>(rotationVector)));
190 }
191
194 static_assert(RequireParameterizableT::value);
195 return internal::fromElements<RotationVectorT>(internal::rotationVectorFromMatrix(quantities_.getValues()));
196 }
197
200 template <AnyQuantities EulerAnglesOtherT_>
201 static PassiveSpatialRotation fromEulerAnglesZyx(const EulerAnglesOtherT_& angles) {
202 static_assert(RequireParameterizableT::value);
203 return makeUnchecked(internal::matrixFromEulerAngles<2, 1, 0, ValuesT>(internal::elements3(EulerAnglesT{angles})));
204 }
205
208 static_assert(RequireParameterizableT::value);
209 return internal::fromElements<EulerAnglesT>(internal::eulerAnglesZyxFromMatrix(quantities_.getValues()));
210 }
211
214 template <AnyQuantities EulerAnglesOtherT_>
215 static PassiveSpatialRotation fromEulerAnglesXyz(const EulerAnglesOtherT_& angles) {
216 static_assert(RequireParameterizableT::value);
217 return makeUnchecked(internal::matrixFromEulerAngles<0, 1, 2, ValuesT>(internal::elements3(EulerAnglesT{angles})));
218 }
219
222 static_assert(RequireParameterizableT::value);
223 return internal::fromElements<EulerAnglesT>(internal::eulerAnglesXyzFromMatrix(quantities_.getValues()));
224 }
225
233 template <AnyTensor FromVectorT_, AnyTensor ToVectorT_>
234 static PassiveSpatialRotation fromTwoVectors(const FromVectorT_& from, const ToVectorT_& to) {
235 static_assert(RequireParameterizableT::value);
236 return PassiveSpatialRotation{internal::matrixFromQuaternion<ValuesT>(internal::quaternionFromTwoVectors(
237 internal::directionElements<typename ParameterizationsT::template AxisT<FromT_>>(from), internal::directionElements<AxisT>(to)))};
238 }
239
240 // The rotations as a manifold (see ActiveSpatialRotation::boxPlus()), with the perturbations of the matrix on the left in To,
241 // like kindr's boxPlus() and boxMinus() of C_TF, or equivalently on the right in From.
242
245 template <AnyTensor RotationVectorOtherT_>
246 PassiveSpatialRotation boxPlus(const RotationVectorOtherT_& rotationVector) const {
247 static_assert(RequireParameterizableT::value);
248 const ValuesT& matrix = quantities_.getValues();
249 return makeUnchecked(internal::boxPlus(matrix, componentsInTo<AngleUnitT>(matrix, rotationVector)));
250 }
251
254 template <typename CoordinateSystemT_ = ToT_, typename FromOtherT_, typename ToOtherT_>
256 static_assert(internal::SameFrames<PassiveSpatialRotation, std::remove_cvref_t<decltype(other)>>::value);
257 static_assert(RequireParameterizableT::value);
258 const ValuesT& matrix = quantities_.getValues();
259 return vectorFromTo<CoordinateSystemT_, AngleUnitT>(matrix, internal::boxMinus(matrix, other.getQuantities().getValues()));
260 }
261
264 template <typename FromOtherT_, typename ToOtherT_>
266 static_assert(internal::SameFrames<PassiveSpatialRotation, std::remove_cvref_t<decltype(other)>>::value);
267 static_assert(RequireParameterizableT::value);
268 return AngleT{internal::norm(internal::boxMinus(quantities_.getValues(), other.getQuantities().getValues()))};
269 }
270
279 template <AnyTensor RotationVectorOtherT_>
280 static auto exponentialMapJacobian(const RotationVectorOtherT_& rotationVector) {
281 static_assert(RequireParameterizableT::value);
282 using CoordinateSystemOtherT = typename GetCoordinateSystem<RotationVectorOtherT_>::type;
283 constexpr bool inFrom = internal::IsInFrom<FromT_, ToT_, CoordinateSystemOtherT>::value;
284 // The right Jacobian in From is the transpose of the left one, by a specialization rather than a conditional operator on
285 // inFrom, which is known at compile time, so that it leaves no code that coverage reports as never executed.
286 return typename ParameterizationsT::template LinearMapT<CoordinateSystemOtherT>{
287 internal::TransposeIf<inFrom>::value(internal::exponentialMapJacobian<ValuesT>(components<AngleUnitT>(rotationVector)))};
288 }
289
290 // The time derivatives of rotations and the angular velocity w of From relative to To, dR/dt = [w]x R for w in To, which equals
291 // R [w]x for w in From, like kindr's GlobalAngularVelocity (To) and LocalAngularVelocity (From) of C_TF.
292
295 template <AnyTensor AngularVelocityOtherT_>
296 MatrixDerivativeT matrixDerivative(const AngularVelocityOtherT_& angularVelocity) const {
297 static_assert(RequireParameterizableT::value);
298 const ValuesT& matrix = quantities_.getValues();
299 return MatrixDerivativeT{internal::matrixDerivative(matrix, componentsInTo<AngularVelocityUnitT>(matrix, angularVelocity))};
300 }
301
304 template <typename CoordinateSystemT_ = ToT_, AnyQuantities MatrixDerivativeOtherT_>
305 auto angularVelocityFromMatrixDerivative(const MatrixDerivativeOtherT_& derivative) const {
306 static_assert(RequireParameterizableT::value);
307 const ValuesT& matrix = quantities_.getValues();
308 return vectorFromTo<CoordinateSystemT_, AngularVelocityUnitT>(
309 matrix, internal::angularVelocityFromMatrixDerivative(matrix, MatrixDerivativeT{derivative}.getValues()));
310 }
311
314 template <AnyQuantities QuaternionOtherT_, AnyTensor AngularVelocityOtherT_>
315 static QuaternionDerivativeT quaternionDerivative(const QuaternionOtherT_& quaternion, const AngularVelocityOtherT_& angularVelocity) {
316 static_assert(RequireParameterizableT::value);
317 const auto elements = internal::quaternionElements(QuaternionT{quaternion});
318 return internal::fromElements<QuaternionDerivativeT>(internal::quaternionDerivative(
319 elements, componentsInTo<AngularVelocityUnitT>(internal::matrixFromQuaternion<ValuesT>(elements), angularVelocity)));
320 }
321
324 template <typename CoordinateSystemT_ = ToT_, AnyQuantities QuaternionOtherT_, AnyQuantities QuaternionDerivativeOtherT_>
325 static auto angularVelocityFromQuaternionDerivative(const QuaternionOtherT_& quaternion, const QuaternionDerivativeOtherT_& derivative) {
326 static_assert(RequireParameterizableT::value);
327 const auto elements = internal::quaternionElements(QuaternionT{quaternion});
328 return vectorFromTo<CoordinateSystemT_, AngularVelocityUnitT>(
329 internal::matrixFromQuaternion<ValuesT>(elements),
330 internal::angularVelocityFromQuaternionDerivative(elements, internal::quaternionElements(QuaternionDerivativeT{derivative})));
331 }
332
335 template <AnyQuantities EulerAnglesOtherT_, AnyTensor AngularVelocityOtherT_>
336 static EulerAnglesDerivativeT eulerAnglesZyxDerivative(const EulerAnglesOtherT_& angles, const AngularVelocityOtherT_& angularVelocity) {
337 static_assert(RequireParameterizableT::value);
338 const auto elements = internal::elements3(EulerAnglesT{angles});
339 return internal::fromElements<EulerAnglesDerivativeT>(internal::eulerAnglesZyxDerivative(
340 elements, componentsInTo<AngularVelocityUnitT>(internal::matrixFromEulerAngles<2, 1, 0, ValuesT>(elements), angularVelocity)));
341 }
342
345 template <typename CoordinateSystemT_ = ToT_, AnyQuantities EulerAnglesOtherT_, AnyQuantities EulerAnglesDerivativeOtherT_>
346 static auto angularVelocityFromEulerAnglesZyxDerivative(const EulerAnglesOtherT_& angles,
347 const EulerAnglesDerivativeOtherT_& derivative) {
348 static_assert(RequireParameterizableT::value);
349 const auto elements = internal::elements3(EulerAnglesT{angles});
350 return vectorFromTo<CoordinateSystemT_, AngularVelocityUnitT>(
351 internal::matrixFromEulerAngles<2, 1, 0, ValuesT>(elements),
352 internal::angularVelocityFromEulerAnglesZyxDerivative(elements, internal::elements3(EulerAnglesDerivativeT{derivative})));
353 }
354
357 template <AnyQuantities EulerAnglesOtherT_, AnyTensor AngularVelocityOtherT_>
358 static EulerAnglesDerivativeT eulerAnglesXyzDerivative(const EulerAnglesOtherT_& angles, const AngularVelocityOtherT_& angularVelocity) {
359 static_assert(RequireParameterizableT::value);
360 const auto elements = internal::elements3(EulerAnglesT{angles});
361 return internal::fromElements<EulerAnglesDerivativeT>(internal::eulerAnglesXyzDerivative(
362 elements, componentsInTo<AngularVelocityUnitT>(internal::matrixFromEulerAngles<0, 1, 2, ValuesT>(elements), angularVelocity)));
363 }
364
367 template <typename CoordinateSystemT_ = ToT_, AnyQuantities EulerAnglesOtherT_, AnyQuantities EulerAnglesDerivativeOtherT_>
368 static auto angularVelocityFromEulerAnglesXyzDerivative(const EulerAnglesOtherT_& angles,
369 const EulerAnglesDerivativeOtherT_& derivative) {
370 static_assert(RequireParameterizableT::value);
371 const auto elements = internal::elements3(EulerAnglesT{angles});
372 return vectorFromTo<CoordinateSystemT_, AngularVelocityUnitT>(
373 internal::matrixFromEulerAngles<0, 1, 2, ValuesT>(elements),
374 internal::angularVelocityFromEulerAnglesXyzDerivative(elements, internal::elements3(EulerAnglesDerivativeT{derivative})));
375 }
376
377 private:
381 template <typename UnitT_, typename VectorT_>
382 static auto components(const VectorT_& vector) {
383 using CoordinateSystemOtherT = typename GetCoordinateSystem<VectorT_>::type;
384 // Rejects other coordinate systems than From and To.
385 static_cast<void>(internal::IsInFrom<FromT_, ToT_, CoordinateSystemOtherT>::value);
387 }
388
391 template <typename UnitT_, typename VectorT_>
392 static auto componentsInTo(const ValuesT& matrix, const VectorT_& vector) {
393 constexpr bool inFrom = internal::IsInFrom<FromT_, ToT_, typename GetCoordinateSystem<VectorT_>::type>::value;
394 return internal::TangentComponents<inFrom>::toTo(matrix, components<UnitT_>(vector));
395 }
396
399 template <typename CoordinateSystemT_, typename UnitT_>
400 static auto vectorFromTo(const ValuesT& matrix, const internal::Elements3<ValueT_>& elementsInTo) {
401 constexpr bool inFrom = internal::IsInFrom<FromT_, ToT_, CoordinateSystemT_>::value;
402 return internal::fromElements<HomogeneousVector<3, ValuesT_, ValueT_, UnitT_, CoordinateSystemT_>>(
403 internal::TangentComponents<inFrom>::fromTo(matrix, elementsInTo));
404 }
405
406 struct Unchecked {};
407 PassiveSpatialRotation(Unchecked /*tag*/, QuantitiesT quantities) : quantities_{std::move(quantities)} {}
408
410 QuantitiesT quantities_;
411};
412
413template <template <typename, int, int> typename ValuesT_, typename ValueT_, typename FromT_, typename ToT_>
415template <template <typename, int, int> typename ValuesT_, typename ValueT_, typename FromT_, typename ToT_>
417
418namespace internal {
419
420template <template <typename, int, int> typename ValuesT_, typename ValueT_, typename FromT_, typename ToT_, int DimensionV_>
421struct IsRotation<PassiveSpatialRotation<ValuesT_, ValueT_, FromT_, ToT_, DimensionV_>> : std::true_type {};
422
423template <template <typename, int, int> typename ValuesT_, typename ValueT_, typename FromT_, typename ToT_, int DimensionV_>
424struct IsChangeOfBasis<PassiveSpatialRotation<ValuesT_, ValueT_, FromT_, ToT_, DimensionV_>> : std::true_type {};
425
426template <template <typename, int, int> typename ValuesT_, typename ValueT_, typename FromT_, typename ToT_, int DimensionV_,
427 typename NewFromT_, typename NewToT_>
428struct WithFrames<PassiveSpatialRotation<ValuesT_, ValueT_, FromT_, ToT_, DimensionV_>, NewFromT_, NewToT_> {
430};
431
432} // namespace internal
433
434// A rotation transforms tensors like the passive linear transformation with its matrix, but with its transpose as the inverse,
435// e.g. for covectors.
436template <template <typename, int, int> typename ValuesT_, typename ValueT_, typename FromT_, typename ToT_, int DimensionV_,
437 typename Object>
438struct TransformationTraits<PassiveSpatialRotation<ValuesT_, ValueT_, FromT_, ToT_, DimensionV_>, Object>
439 : TransformationTraits<typename PassiveSpatialRotation<ValuesT_, ValueT_, FromT_, ToT_, DimensionV_>::LinearTransformationT, Object> {};
440
441// The composition X_AB * X_BC = X_AC of two rotations is the rotation R_AB R_BC.
442template <template <typename, int, int> typename ValuesLhsT_, typename ValueLhsT_, typename FromLhsT_, typename ToLhsT_, int DimensionLhsV_,
443 template <typename, int, int> typename ValuesRhsT_, typename ValueRhsT_, typename FromRhsT_, typename ToRhsT_, int DimensionRhsV_>
444struct CompositionTraits<PassiveSpatialRotation<ValuesLhsT_, ValueLhsT_, FromLhsT_, ToLhsT_, DimensionLhsV_>,
445 PassiveSpatialRotation<ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionRhsV_>> {
448 return internal::WithFrames<LhsT, FromRhsT_, ToLhsT_>::type::makeUnchecked(innerProduct(lhs.getQuantities(), rhs.getQuantities()));
449 }
450};
451
452// A rotation is a linear transformation: its compositions with linear transformations are those of the linear transformation with
453// its matrix, the products of the matrices.
454template <template <typename, int, int> typename ValuesLhsT_, typename ValueLhsT_, typename FromLhsT_, typename ToLhsT_, int DimensionLhsV_,
455 template <typename, int, int> typename ValuesRhsT_, typename ValueRhsT_, typename FromRhsT_, typename ToRhsT_, int DimensionRhsV_,
456 typename... UnitsRhsT_>
457struct CompositionTraits<PassiveSpatialRotation<ValuesLhsT_, ValueLhsT_, FromLhsT_, ToLhsT_, DimensionLhsV_>,
458 PassiveLinearTransformation<ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionRhsV_, UnitsRhsT_...>>
459 : CompositionTraits<typename PassiveSpatialRotation<ValuesLhsT_, ValueLhsT_, FromLhsT_, ToLhsT_, DimensionLhsV_>::LinearTransformationT,
460 PassiveLinearTransformation<ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionRhsV_, UnitsRhsT_...>> {};
461
462template <template <typename, int, int> typename ValuesLhsT_, typename ValueLhsT_, typename FromLhsT_, typename ToLhsT_, int DimensionLhsV_,
463 typename... UnitsLhsT_, template <typename, int, int> typename ValuesRhsT_, typename ValueRhsT_, typename FromRhsT_,
464 typename ToRhsT_, int DimensionRhsV_>
465struct CompositionTraits<PassiveLinearTransformation<ValuesLhsT_, ValueLhsT_, FromLhsT_, ToLhsT_, DimensionLhsV_, UnitsLhsT_...>,
466 PassiveSpatialRotation<ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionRhsV_>>
468 PassiveLinearTransformation<ValuesLhsT_, ValueLhsT_, FromLhsT_, ToLhsT_, DimensionLhsV_, UnitsLhsT_...>,
469 typename PassiveSpatialRotation<ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionRhsV_>::LinearTransformationT> {};
470
471// The compositions X_AB * X_BC = X_AC of a rotation with a translation or a proper rigid transformation are proper rigid
472// transformations, with a rotation and a translation of the kinds of the operands, or of those of the proper rigid operand (see
473// internal/rigid.hpp).
474
475template <template <typename, int, int> typename ValuesLhsT_, typename ValueLhsT_, typename FromLhsT_, typename ToLhsT_, int DimensionLhsV_,
476 template <typename, int, int> typename ValuesRhsT_, int DimensionRhsV_, typename ValueRhsT_, typename FromRhsT_, typename ToRhsT_,
477 typename... UnitsRhsT_>
478struct CompositionTraits<PassiveSpatialRotation<ValuesLhsT_, ValueLhsT_, FromLhsT_, ToLhsT_, DimensionLhsV_>,
479 PassiveTranslation<ValuesRhsT_, DimensionRhsV_, ValueRhsT_, FromRhsT_, ToRhsT_, UnitsRhsT_...>> {
481 using RhsT = PassiveTranslation<ValuesRhsT_, DimensionRhsV_, ValueRhsT_, FromRhsT_, ToRhsT_, UnitsRhsT_...>;
482 static auto compose(const LhsT& lhs, const RhsT& rhs) {
483 return internal::composeRotationAndTranslation<internal::PassiveRigidOf<LhsT, RhsT, FromRhsT_, ToLhsT_>>(lhs, rhs);
484 }
485};
486
487template <template <typename, int, int> typename ValuesLhsT_, int DimensionLhsV_, typename ValueLhsT_, typename FromLhsT_, typename ToLhsT_,
488 typename... UnitsLhsT_, template <typename, int, int> typename ValuesRhsT_, typename ValueRhsT_, typename FromRhsT_,
489 typename ToRhsT_, int DimensionRhsV_>
490struct CompositionTraits<PassiveTranslation<ValuesLhsT_, DimensionLhsV_, ValueLhsT_, FromLhsT_, ToLhsT_, UnitsLhsT_...>,
491 PassiveSpatialRotation<ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionRhsV_>> {
492 using LhsT = PassiveTranslation<ValuesLhsT_, DimensionLhsV_, ValueLhsT_, FromLhsT_, ToLhsT_, UnitsLhsT_...>;
494 static auto compose(const LhsT& lhs, const RhsT& rhs) {
495 return internal::composeTranslationAndRotation<internal::PassiveRigidOf<RhsT, LhsT, FromRhsT_, ToLhsT_>>(lhs, rhs);
496 }
497};
498
499template <typename FromLhsT_, typename ToLhsT_, typename RotationLhsT_, typename TranslationLhsT_,
500 template <typename, int, int> typename ValuesRhsT_, typename ValueRhsT_, typename FromRhsT_, typename ToRhsT_, int DimensionRhsV_>
501struct CompositionTraits<PassiveProperRigidTransformationTemplate<FromLhsT_, ToLhsT_, RotationLhsT_, TranslationLhsT_>,
502 PassiveSpatialRotation<ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionRhsV_>> {
505 return internal::composeRigidAndRotation<internal::PassiveRigidWithFrames<LhsT, FromRhsT_, ToLhsT_>>(lhs, rhs);
506 }
507};
508
509template <template <typename, int, int> typename ValuesLhsT_, typename ValueLhsT_, typename FromLhsT_, typename ToLhsT_, int DimensionLhsV_,
510 typename FromRhsT_, typename ToRhsT_, typename RotationRhsT_, typename TranslationRhsT_>
511struct CompositionTraits<PassiveSpatialRotation<ValuesLhsT_, ValueLhsT_, FromLhsT_, ToLhsT_, DimensionLhsV_>,
512 PassiveProperRigidTransformationTemplate<FromRhsT_, ToRhsT_, RotationRhsT_, TranslationRhsT_>> {
515 return internal::composeRotationAndRigid<internal::PassiveRigidWithFrames<RhsT, FromRhsT_, ToLhsT_>>(lhs, rhs);
516 }
517};
518
519template <template <typename, int, int> typename ValuesLhsT_, typename ValueLhsT_, typename FromLhsT_, typename ToLhsT_, int DimensionLhsV_,
520 template <typename, int, int> typename ValuesRhsT_, typename ValueRhsT_, typename FromRhsT_, typename ToRhsT_, int DimensionRhsV_>
523 static_assert(internal::SameFrames<std::remove_cvref_t<decltype(lhs)>, std::remove_cvref_t<decltype(rhs)>>::value);
524 return lhs.getQuantities() == rhs.getQuantities();
525}
526
527template <template <typename, int, int> typename ValuesLhsT_, typename ValueLhsT_, typename FromLhsT_, typename ToLhsT_, int DimensionLhsV_,
528 template <typename, int, int> typename ValuesRhsT_, typename ValueRhsT_, typename FromRhsT_, typename ToRhsT_, int DimensionRhsV_>
533
534template <template <typename, int, int> typename ValuesT_, typename ValueT_, typename FromT_, typename ToT_, int DimensionV_>
536 lhs << rhs.getQuantities();
537 return lhs;
538}
539
540} // namespace wuzp
A passive linear transformation, i.e. a change of basis, from the coordinate system From to the coord...
ValuesT_< ValueT_, DimensionV_, DimensionV_ > ValuesT
TypeMatrix< DimensionV_, DimensionV_, UnitsT_... > UnitsT
A passive proper rigid transformation from From to To, which first rotates, then translates: p -> R p...
A passive rotation from the coordinate system From to the coordinate system To, which have the same o...
EulerAnglesT toEulerAnglesZyx() const
The Euler angles ZYX of the matrix (see ActiveSpatialRotation::toEulerAnglesZyx()).
static EulerAnglesDerivativeT eulerAnglesXyzDerivative(const EulerAnglesOtherT_ &angles, const AngularVelocityOtherT_ &angularVelocity)
The derivatives of the Euler angles XYZ of the matrix for the angular velocity w, in To or in From,...
typename ParameterizationsT::AngleT AngleT
An angle, e.g. of a rotation around its axis, or between two rotations.
static PassiveSpatialRotation fromQuaternion(const QuaternionOtherT_ &quaternion)
The rotation of the unit quaternion q, whose matrix is that of ActiveSpatialRotation::fromQuaternion(...
typename ParameterizationsT::MatrixDerivativeT MatrixDerivativeT
The derivative dR/dt of the matrix of a rotation with respect to time.
static PassiveSpatialRotation fromEulerAnglesXyz(const EulerAnglesOtherT_ &angles)
The rotation whose matrix has the Euler angles XYZ (a0, a1, a2), R = R_x(a0) R_y(a1) R_z(a2) (see Act...
MatrixDerivativeT matrixDerivative(const AngularVelocityOtherT_ &angularVelocity) const
The derivative dR/dt = [w]x R of the matrix for the angular velocity w in To, which equals R [w]x for...
PassiveSpatialRotation()
The identity: From and To have the same axes.
static auto angularVelocityFromQuaternionDerivative(const QuaternionOtherT_ &quaternion, const QuaternionDerivativeOtherT_ &derivative)
The angular velocity of the derivative dq/dt of the unit quaternion q, expressed in To or,...
typename ParameterizationsT::EulerAnglesDerivativeT EulerAnglesDerivativeT
The derivatives of three Euler angles with respect to time.
typename ParameterizationsT::template RotationVectorT< ToT_ > RotationVectorT
A rotation vector angle * axis, expressed in To, e.g. the logarithm of a rotation or an increment of ...
RotationVectorT toRotationVector() const
The logarithmic map Log(R) of the matrix, the rotation vector of the rotation, with an angle in [0,...
typename LinearTransformationT::ValuesT ValuesT
AngleAxisT toAngleAxis() const
The angle in [0, pi] and the unit axis of the matrix (see ActiveSpatialRotation::toAngleAxis()).
AngleT angularDistance(const PassiveSpatialRotation< ValuesT_, ValueT_, FromOtherT_, ToOtherT_, DimensionV_ > &other) const
The angle in [0, pi] of the rotation between this and the other rotation, the norm of boxMinus(other)...
typename ParameterizationsT::template AxisT< ToT_ > AxisT
The unit axis of a rotation, expressed in To. The rotation leaves its axis unchanged,...
typename LinearTransformationT::UnitsT UnitsT
typename ParameterizationsT::QuaternionDerivativeT QuaternionDerivativeT
The derivative dq/dt of a quaternion with respect to time, in the unit of an angular velocity.
static PassiveSpatialRotation fromTwoVectors(const FromVectorT_ &from, const ToVectorT_ &to)
The rotation with the smallest angle under which the direction of the vector from,...
auto boxMinus(const PassiveSpatialRotation< ValuesT_, ValueT_, FromOtherT_, ToOtherT_, DimensionV_ > &other) const
The rotation vector Log(R S^T) of the matrices R of this rotation and S of the other one,...
static auto angularVelocityFromEulerAnglesZyxDerivative(const EulerAnglesOtherT_ &angles, const EulerAnglesDerivativeOtherT_ &derivative)
The angular velocity of the derivatives of the Euler angles ZYX of the matrix, expressed in To or,...
static PassiveSpatialRotation makeUnchecked(Args &&... args)
The rotation whose matrix is constructed from the arguments, without checking it, like Drake's Rotati...
PassiveLinearTransformation< ValuesT_, ValueT_, FromT_, ToT_, DimensionV_, typename AccessUnits< AccessImplementation< ValueT_ > >::Dimensionless > LinearTransformationT
The passive linear transformation with the matrix of the rotation, whose transformations the rotation...
EulerAnglesT toEulerAnglesXyz() const
The Euler angles XYZ of the matrix (see ActiveSpatialRotation::toEulerAnglesXyz()).
static auto exponentialMapJacobian(const RotationVectorOtherT_ &rotationVector)
The Jacobian J of the exponential map at the rotation vector v, a linear map in the coordinate system...
bool isApprox(const PassiveSpatialRotation< ValuesOtherT_, ValueOtherT_, FromOtherT_, ToOtherT_, DimensionOtherV_ > &other, const ValueT precision=Precision< ValueT >::value()) const
Whether both rotations, which must transform between the same coordinate systems, are approximately e...
static PassiveSpatialRotation projectToRotation(Args &&... args)
The rotation nearest to the matrix constructed from the arguments, e.g. to a rotation whose rounding ...
typename ParameterizationsT::EulerAnglesT EulerAnglesT
Three Euler angles, in the order of the axes in their name, e.g. (yaw, pitch, roll) for ZYX.
static EulerAnglesDerivativeT eulerAnglesZyxDerivative(const EulerAnglesOtherT_ &angles, const AngularVelocityOtherT_ &angularVelocity)
The derivatives of the Euler angles ZYX of the matrix for the angular velocity w, in To or in From,...
auto angularVelocityFromMatrixDerivative(const MatrixDerivativeOtherT_ &derivative) const
The angular velocity of the derivative dR/dt of the matrix, [w]x = dR/dt R^T in To,...
PassiveSpatialRotation boxPlus(const RotationVectorOtherT_ &rotationVector) const
The rotation whose matrix R is rotated further by the rotation vector v: Exp(v) R for v in To,...
static PassiveSpatialRotation fromEulerAnglesZyx(const EulerAnglesOtherT_ &angles)
The rotation whose matrix has the Euler angles ZYX (yaw, pitch, roll), R = R_z(yaw) R_y(pitch) R_x(ro...
typename LinearTransformationT::QuantitiesT QuantitiesT
static auto angularVelocityFromEulerAnglesXyzDerivative(const EulerAnglesOtherT_ &angles, const EulerAnglesDerivativeOtherT_ &derivative)
The angular velocity of the derivatives of the Euler angles XYZ of the matrix, expressed in To or,...
std::pair< AngleT, AxisT > AngleAxisT
The angle and the unit axis of a rotation.
static PassiveSpatialRotation fromAngleAxis(const AngleOtherT_ &angle, const AxisOtherT_ &axis)
The rotation whose matrix rotates by an angle around a unit axis, right-handed, which is expressed in...
QuaternionT toQuaternion() const
The unique unit quaternion of the matrix (see ActiveSpatialRotation::toQuaternion()).
PassiveSpatialRotation(Args &&... args)
The rotation whose matrix is constructed from the arguments, e.g. its elements row by row,...
static PassiveSpatialRotation fromRotationVector(const RotationVectorOtherT_ &rotationVector)
The rotation whose matrix is the exponential map Exp(v) of the rotation vector v, which is expressed ...
bool isValid(const ValueT tolerance=ValidityTolerance< ValueT >::value()) const
Whether the matrix is a rotation: max_ij |(R R^T - I)_ij| <= tolerance, and det(R) > 0 (see internal:...
const QuantitiesT & getQuantities() const
The matrix R, which transforms the components v of a vector in From into its components R v in To.
typename ParameterizationsT::template AngularVelocityT< ToT_ > AngularVelocityT
The angular velocity of From relative to To, expressed in To. It may also be expressed in From.
static QuaternionDerivativeT quaternionDerivative(const QuaternionOtherT_ &quaternion, const AngularVelocityOtherT_ &angularVelocity)
The derivative dq/dt = (0, w) q / 2 of the unit quaternion q for the angular velocity w in To,...
typename ParameterizationsT::QuaternionT QuaternionT
A unit quaternion (w, x, y, z) of the matrix (see ActiveSpatialRotation::QuaternionT),...
auto inverse() const
The inverse rotation, from To to From, whose matrix is the transpose R^T = R^-1: it needs no matrix i...
A passive transformation, which expresses the objects of the coordinate system From in the coordinate...
A passive translation from the coordinate system From to the coordinate system To,...
const ValuesT & getValues() const &
Get the values of the quantities.
The alias template ValueMatrix<ValueT_, RowsV_, ColsV_> of any value matrix backend,...
Definition concepts.hpp:89
Whether constructing a Class from the arguments copies or moves it, i.e. whether they are a single Cl...
Definition helpers.hpp:69
A coordinate system with the Euclidean metric, the default, e.g. CoordinateSystem<World>: the coordin...
Definition concepts.hpp:35
bool operator!=(const Quantities< ValuesLhsT_, UnitsLhsT_ > &lhs, const Quantities< ValuesRhsT_, UnitsRhsT_ > &rhs)
std::ostream & operator<<(std::ostream &lhs, const Quantities< ValuesT_, UnitsT_ > &rhs)
auto innerProduct(const Quantities< ValuesLhsT_, UnitsLhsT_ > &lhs, const Quantities< ValuesRhsT_, UnitsRhsT_ > &rhs)
PassiveSpatialRotation< ValuesT_, ValueT_, FromT_, ToT_, 3 > PassiveSpatialRotation3
bool operator==(const Quantities< ValuesLhsT_, UnitsLhsT_ > &lhs, const Quantities< ValuesRhsT_, UnitsRhsT_ > &rhs)
PassiveSpatialRotation< ValuesT_, ValueT_, FromT_, ToT_, 2 > PassiveSpatialRotation2
Vector< Quantities< ValuesT_< ValueT_, DimensionV_, 1 >, TypeMatrix< DimensionV_, 1, UnitT_ > >, CoordinateSystemT_ > HomogeneousVector
Definition Tensor.hpp:945
The units for values of the arithmetic type ValueT_, e.g. double, specialized for AccessImplementatio...
Definition traits.hpp:338
The composition lhs * rhs of two transformations, which applies rhs first, then lhs: (lhs * rhs)....
Definition traits.hpp:39
static constexpr ValueT_ value()
Definition traits.hpp:356
How a transformation transforms an object: static auto transform(const TransformationT_&,...
Definition traits.hpp:19
static constexpr ValueT_ value()
Definition traits.hpp:58