R3::basic_translation
namespace nin::R3 {
template <std::floating_point T>
struct basic_translation;
using translation = basic_translation<double>;
}
A 3D translation transformation. It shifts coordinates by (Δx, Δy, Δz) expressed as length quantities. Translations are composable, invertible and callable on basic_position_qty. Translations are transformations and cannot be associated to coordinate systems the way that position quantities can do.
The type alias R3::translation is provided for R3::basic_translation<double>.
Nested types
| Type | Definition |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
forward iterator over the three components |
|
const forward iterator over the three components |
Member functions
(Constructor)
(Constructor)
|
(1) |
|
(2) |
-
(1) Default constructor. All components are zero.
-
(2) Component constructor.
import ninbot;
using namespace nin;
int main() {
R3::translation tran_0; // (0, 0, 0) (m)
R3::translation tran_1 = {10_cm, 20_cm, 5_cm}; // (0.1, 0.2, 0.05) (m)
}
invert
inverts the translation in place
invert
inverts the translation in place
|
(1) |
Inverts the transformation by negating all components.
Returns a reference to *this.
import ninbot;
using namespace nin;
int main() {
R3::translation tran = {10_cm, 20_cm, 5_cm};
tran.invert(); // tran = (-10, -20, -5) (cm)
}
operator()
applies the translation to a point quantity
operator()
applies the translation to a point quantity
|
(1) |
Returns a new position quantity obtained by adding the translation to the input argument component-wise.
import ninbot;
using namespace nin;
int main() {
R3::point_qty pt = {1_m, 2_m, 3_m};
R3::translation tran = {10_cm, 20_cm, 0_m};
R3::point_qty pt2 = tran(pt); // pt2 = (1.1, 2.2, 3) (m)
}
operator[]
component access by index
operator[]
component access by index
|
(1) |
|
(2) |
Index 0 returns Δx; index 1 returns Δy; any other index returns Δz.
begin, cbegin
iterator to the first component
begin, cbegin
iterator to the first component
|
(1) |
|
(2) |
|
(3) |
Returns an iterator to the Δx component.
import ninbot;
using namespace nin;
int main() {
R3::translation tran = {10_cm, 20_cm, 5_cm};
for (units::length component : tran)
{ /* iterates over Δx, Δy, then Δz */ }
}
end, cend
sentinel
end, cend
sentinel
|
(1) |
|
(2) |
|
(3) |
Returns a sentinel for iterating over the components.
import ninbot;
using namespace nin;
int main() {
R3::translation tran = {10_cm, 20_cm, 5_cm};
for (units::length component : tran)
{ /* iterates over Δx, Δy, then Δz */ }
}
size
number of components
size
number of components
|
(1) |
Returns 3.
max_size
maximum number of components
max_size
maximum number of components
|
(1) |
Returns 3.
empty
whether the container holds no components
empty
whether the container holds no components
|
(1) |
Returns false.
operator==
equality comparison
operator==
equality comparison
|
(1) |
Componentwise equality.
Non-member functions
inv
inverse translation
inv
inverse translation
|
(1) |
Returns the inverted translation of the argument.
import ninbot;
using namespace nin;
int main() {
R3::translation tran = {10_cm, 20_cm, 5_cm};
R3::translation trani = inv(tran); // trani = (-10, -20, -5) (cm)
}
compose
composes two translations
compose
composes two translations
|
(1) |
Returns the translation whose effect is the composition of the two translations. Composition of translations is commutative.
import ninbot;
using namespace nin;
int main() {
R3::translation tran1 = {10_cm, 0_m, 3_m };
R3::translation tran2 = { 0_m, 20_cm, 3_m };
R3::translation tran = compose(tran1, tran2); // tran = (10, 20, 600) (cm)
}
std::formatter<>
STL overload for the std::format and std::print families.
std::formatter<>
STL overload for the std::format and std::print families.
|
(1) |
Adds a specialization of std::formatter that formats the
three components in the order Δx, Δy, Δz.
The <format-spec> syntax is
[<float-spec>] [ "_" [<unit>] ] [ "|" <separator> ]
with the following rules:
-
<float-spec>— anything before the first_or|is forwarded verbatim to the STL formatter for floating points and applied to formatting each component. -
<unit>— the text betweenand|(or the end of the spec) selects the unit used both for the displayed values and the trailing unit label. When theis present but<unit>is empty, the unit label is suppressed and magnitudes are formatted in SI units. -
Parentheses — when the format-spec contains no
|separator, the output is wrapped in parentheses. -
Separator — the text after
|is placed between the components. Theis not required in order to specify a separator: whenis omitted, the trailing unit label is the default SI label (e.g. ` (m)), and parentheses are dropped as soon as `|is present. When neither_nor|is given,<separator>defaults to", ".
import ninbot;
#include <print>
int main() {
nin::R3::translation t = {1.5_m, 2.0_m, 300_mm};
std::println("{}", t); // "(1.5, 2, 0.3) (m)"
std::println("{:_}", t); // "(1.5, 2, 0.3)"
std::println("{:|, }", t); // "1.5, 2, 0.3 (m)"
std::println("{:.2f| }", t); // "1.50 2.00 0.30 (m)"
std::println("{:_m|, }", t); // "1.5, 2, 0.3 (m)"
std::println("{:.2f_m}", t); // "(1.50, 2.00, 0.30) (m)"
std::println("{:.2f_m|; }", t); // "1.50; 2.00; 0.30 (m)"
std::println("({:.3f_cm| - })", t); // "(150.000 - 200.000 - 30.000 (cm))"
std::println("{:.2f_|, } m", t); // "1.50, 2.00, 0.30 m"
}