wuzp
Wrong Unit? Zero Points! Compile-time checks for units, coordinate systems and points vs. vectors.
Loading...
Searching...
No Matches
PassiveTranslation.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <ostream>
4#include <type_traits>
5#include <utility>
6
12#include "wuzp/core/helpers.hpp"
13#include "wuzp/core/traits.hpp"
15#include "wuzp/trafo/internal/translate.hpp"
16#include "wuzp/trafo/traits.hpp"
17
18namespace wuzp {
19
30template <template <typename, int, int> typename ValuesT_, int DimensionV_, typename ValueT_, AnyCoordinateSystem FromT_,
31 AnyCoordinateSystem ToT_, typename... UnitsT_>
34 : public PassiveTransformation<PassiveTranslation<ValuesT_, DimensionV_, ValueT_, FromT_, ToT_, UnitsT_...>, FromT_, ToT_> {
35 public:
36 using ValueT = ValueT_;
37 using ValuesT = ValuesT_<ValueT_, DimensionV_, 1>;
38 using UnitsT = TypeMatrix<DimensionV_, 1, UnitsT_...>;
41
42 // Copies and moves are left to the implicit constructors, see CopiesOrMoves.
43 template <typename... Args>
44 requires(!CopiesOrMoves<PassiveTranslation, Args...>)
45 explicit PassiveTranslation(Args&&... args) : tensor_{std::forward<Args>(args)...} {}
46
48 const TensorT& getTensor() const { return tensor_; }
50 const QuantitiesT& getQuantities() const { return tensor_.getQuantities(); }
51
53 auto inverse() const { return typename internal::WithFrames<PassiveTranslation, ToT_, FromT_>::type{-getQuantities()}; }
54
57 template <template <typename, int, int> typename ValuesOtherT_, int DimensionOtherV_, typename ValueOtherT_, typename FromOtherT_,
58 typename ToOtherT_, typename... UnitsOtherT_>
60 const ValueT precision = Precision<ValueT>::value()) const {
61 static_assert(internal::SameFrames<PassiveTranslation, std::remove_cvref_t<decltype(other)>>::value);
62 return tensor_.isApprox(other.getTensor(), precision);
63 }
64
65 private:
67 TensorT tensor_;
68};
69
70namespace internal {
71
72template <template <typename, int, int> typename ValuesT_, int DimensionV_, typename ValueT_, typename FromT_, typename ToT_,
73 typename... UnitsT_, typename NewFromT_, typename NewToT_>
74struct WithFrames<PassiveTranslation<ValuesT_, DimensionV_, ValueT_, FromT_, ToT_, UnitsT_...>, NewFromT_, NewToT_> {
75 using type = PassiveTranslation<ValuesT_, DimensionV_, ValueT_, NewFromT_, NewToT_, UnitsT_...>;
76};
77
78} // namespace internal
79
80// A passive translation moves points, leaves vectors, covectors and tensors with two upper indices unchanged, and rejects the
81// other tensors (see internal::translate()). It takes the object by a forwarding reference, so that a temporary vector is moved
82// rather than copied.
83template <template <typename, int, int> typename ValuesT_, int DimensionV_, typename ValueT_, typename FromT_, typename ToT_,
84 typename... UnitsT_, typename IndicesOtherT_, typename QuantitiesOtherT_, typename CoordinateSystemOtherT_,
85 typename AbsoluteOtherT_>
86struct TransformationTraits<PassiveTranslation<ValuesT_, DimensionV_, ValueT_, FromT_, ToT_, UnitsT_...>,
87 Tensor<IndicesOtherT_, QuantitiesOtherT_, CoordinateSystemOtherT_, AbsoluteOtherT_>> {
89 template <typename ObjectT_>
90 requires std::is_same_v<std::remove_cvref_t<ObjectT_>, ObjectT>
92 ObjectT_&& object) {
93 // The object is expressed in From (see PassiveTransformation::transform()), whose axes are those of To, in which the vector of
94 // the translation is expressed.
95 return internal::translate<ToT_>(std::forward<ObjectT_>(object), transformation.getQuantities());
96 }
97};
98
99// The composition X_AB * X_BC = X_AC of two translations is the translation by the sum of their vectors, p_AoCo_A = p_AoBo_A +
100// p_BoCo_B: A, B and C have the same axes, so the components of p_BoCo are the same in B and A.
101template <template <typename, int, int> typename ValuesLhsT_, int DimensionLhsV_, typename ValueLhsT_, typename FromLhsT_, typename ToLhsT_,
102 typename... UnitsLhsT_, template <typename, int, int> typename ValuesRhsT_, int DimensionRhsV_, typename ValueRhsT_,
103 typename FromRhsT_, typename ToRhsT_, typename... UnitsRhsT_>
104struct CompositionTraits<PassiveTranslation<ValuesLhsT_, DimensionLhsV_, ValueLhsT_, FromLhsT_, ToLhsT_, UnitsLhsT_...>,
105 PassiveTranslation<ValuesRhsT_, DimensionRhsV_, ValueRhsT_, FromRhsT_, ToRhsT_, UnitsRhsT_...>> {
106 using LhsT = PassiveTranslation<ValuesLhsT_, DimensionLhsV_, ValueLhsT_, FromLhsT_, ToLhsT_, UnitsLhsT_...>;
107 static auto compose(const LhsT& lhs,
109 return typename internal::WithFrames<LhsT, FromRhsT_, ToLhsT_>::type{lhs.getQuantities() + rhs.getQuantities()};
110 }
111};
112
113template <template <typename, int, int> typename ValuesLhsT_, int DimensionLhsV_, typename ValueLhsT_, typename FromLhsT_, typename ToLhsT_,
114 typename... UnitsLhsT_, template <typename, int, int> typename ValuesRhsT_, int DimensionRhsV_, typename ValueRhsT_,
115 typename FromRhsT_, typename ToRhsT_, typename... UnitsRhsT_>
118 static_assert(internal::SameFrames<std::remove_cvref_t<decltype(lhs)>, std::remove_cvref_t<decltype(rhs)>>::value);
119 return lhs.getTensor() == rhs.getTensor();
120}
121
122template <template <typename, int, int> typename ValuesLhsT_, int DimensionLhsV_, typename ValueLhsT_, typename FromLhsT_, typename ToLhsT_,
123 typename... UnitsLhsT_, template <typename, int, int> typename ValuesRhsT_, int DimensionRhsV_, typename ValueRhsT_,
124 typename FromRhsT_, typename ToRhsT_, typename... UnitsRhsT_>
129
130template <template <typename, int, int> typename ValuesT_, int DimensionV_, typename ValueT_, typename FromT_, typename ToT_,
131 typename... UnitsT_>
133 lhs << rhs.getTensor();
134 return lhs;
135}
136
137template <template <typename, int, int> typename ValuesT_, int DimensionV_, typename ValueT_, typename FromT_, typename ToT_>
140template <template <typename, int, int> typename ValuesT_, typename ValueT_, typename FromT_, typename ToT_>
142template <template <typename, int, int> typename ValuesT_, typename ValueT_, typename FromT_, typename ToT_>
144
145// v == 0 -> Translation
146// a == 0 -> Uniform motion
147// da/dt == 0 -> Motion with constant acceleration.
148
149// omega == 0 -> Rotation
150// phi == 0 -> Uniform circular motion
151// phi/dt == 0 -> Circular motion with constant acceleration.
152
153} // namespace wuzp
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 TensorT & getTensor() const
The vector t from the origin of To to the origin of From, expressed in To.
auto inverse() const
The inverse translation, from To to From, whose vector from the origin of From to the origin of To is...
bool isApprox(const PassiveTranslation< ValuesOtherT_, DimensionOtherV_, ValueOtherT_, FromOtherT_, ToOtherT_, UnitsOtherT_... > &other, const ValueT precision=Precision< ValueT >::value()) const
Whether both translations, which must transform between the same coordinate systems,...
PassiveTranslation(Args &&... args)
const QuantitiesT & getQuantities() const
The components of the translation, like getQuantities() of the linear transformations.
Container to store quantities.
A tensor of rank 0, 1 or 2, whose components are quantities, expressed in a coordinate system,...
Definition Tensor.hpp:99
Any coordinate system: a specialization of CoordinateSystem, including the intermediate ones of trans...
Definition concepts.hpp:30
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
PassiveSpatialTranslation< ValuesT_, 2, ValueT_, FromT_, ToT_ > PassiveSpatialTranslation2
PassiveTranslation< ValuesT_, DimensionV_, ValueT_, FromT_, ToT_, typename AccessUnits< AccessImplementation< ValueT_ > >::Length > PassiveSpatialTranslation
bool operator!=(const Quantities< ValuesLhsT_, UnitsLhsT_ > &lhs, const Quantities< ValuesRhsT_, UnitsRhsT_ > &rhs)
std::ostream & operator<<(std::ostream &lhs, const Quantities< ValuesT_, UnitsT_ > &rhs)
PassiveSpatialTranslation< ValuesT_, 3, ValueT_, FromT_, ToT_ > PassiveSpatialTranslation3
internal::AbsoluteImpl< false > Relative
Definition Absolute.hpp:18
bool operator==(const Quantities< ValuesLhsT_, UnitsLhsT_ > &lhs, const Quantities< ValuesRhsT_, UnitsRhsT_ > &rhs)
typename CreateTypeMatrix< RowsV_, ColsV_, Types... >::type TypeMatrix
A matrix storing types at compile-time.
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