R2::basic_rotation
namespace nin::R2 {
template <std::floating_point T>
class basic_rotation;
using rotation = basic_rotation<double>;
}
A 2D rotation transformation. Parameterised by a single angle, it is composable, invertible, and callable on R2::basic_position_qty, R2::basic_orientation_qty, and on plain fixed-size containers of two position coordinates.
| Rotations differ from orientations: * Conceptually, they are transformations as opposed to coordinates in SO(2). * Numerically, they retain the number of full revolutions taken to reach the angle. See basic_orientation_qty for the coordinate quantity counterpart. |
The type alias rotation is provided for basic_rotation<double>.
Member functions
(Constructor)
(Constructor)
|
(1) |
|
(2) |
|
(3) |
|
(4) |
-
(1) The default constructor is the identity rotation.
-
(2) Copy constructor from a different floating-point precision.
-
(3) Constructs from an angle.
-
(4) Constructs the rotation that brings
referenceontomeasure(both of typeR2::orientation_qty), plus an optional integer number of full revolutions.
import ninbot;
using namespace nin;
int main() {
R2::rotation rot0; // 0°
R2::rotation rot1 { 720_deg };
}
invert
inverts the rotation
invert
inverts the rotation
|
(1) |
Inverts the rotation in place.
Returns a reference to *this to allow chaining.
import ninbot;
using namespace nin;
int main() {
R2::rotation rot { 20_deg };
rot.invert(); // rot is now -20°
}
angle
rotation angle
angle
rotation angle
|
(1) |
|
(2) |
import ninbot;
using namespace nin;
int main() {
R2::rotation rot { 45_deg };
rot.angle() += 90_deg; // rot is now 135°
}
operator()
applies the rotation
operator()
applies the rotation
|
(1) |
|
(2) |
|
(3) |
-
(1) Rotates a raw 2-component vector and returns a value of the same container type.
-
(2) Rotates a
R2::basic_orientation_qty. -
(3) Rotates a
R2::basic_position_qty(a.k.a.point_qty).
import ninbot;
using namespace nin;
int main() {
R2::rotation rot { 90_deg };
R2::point_qty pt { 1_m, 0_m };
R2::point_qty qty = rot(pt); // q ≈ (0, 1) (m)
R2::orientation_qty ori = r(); // default orientation rotated by 90°
}
Non-member functions
inv
returns the inverse rotation
inv
returns the inverse rotation
|
(1) |
Returns the inverse of the argument rotation, of type R2::basic_rotation.
import ninbot;
using namespace nin;
int main() {
R2::rotation rot { 75_deg };
R2::rotation roti = inv(rot); // roti = -75°
}
compose
composes two rotations
compose
composes two rotations
|
(1) |
returns the composition of lhs with rhs.
Both lhs and rhs are of type R2::basic_rotation.
import ninbot;
using namespace nin;
int main() {
R2::rotation rot1 { 45_deg };
R2::rotation rot2 { 90_deg };
R2::rotation rot = compose(rot2, rot1); // rot = 135°
}
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 rotation as an angle.
The <format-spec> syntax is
[<float-spec>] [ "_" <unit> ]
with the following rules:
-
<float-spec>— anything before the first_is forwarded verbatim to the STL formatter for floating points. -
<unit>— the text afterselects the unit used for the displayed value and the trailing unit label. Must be dimensionally compatible withunits::angle_v<T>(e.g.rad,deg). The literaldegis rendered as a degree sign°without a leading space; every other unit is rendered with a leading space (e.g. ` rad`). When theis omitted, the default unit label ` rad` is appended.
import ninbot;
#include <print>
int main() {
nin::R2::rotation r90 { 90_deg };
nin::R2::rotation r_multi { 1170_deg }; // 3 turns + 90°
std::println("{}", r90); // "1.5707963267948966 rad"
std::println("{:_deg}", r90); // "90°"
std::println("{:.1f_deg}", r90); // "90.0°"
std::println("{:.2f_rad}", r90); // "1.57 rad"
std::println("{:.1f_deg}", r_multi); // "1170.0°"
}