R2::basic_orientation_qty
namespace nin::R2 {
template <std::floating_point T>
class basic_orientation_qty;
using orientation_qty = basic_orientation_qty<double>;
}
A 2D orientation quantity. It represents the angular state of a body in the plane. It is an abstract realisation of raw orientation coordinates with no relation to any coordinate system. The interface deliberately hides the underlying representation, exposing only the operations relevant to reasoning in terms of orientation operations.
Orientations are coordinates, not transformations. They have no
compose() or inv() functions.
To transform orientations and other objects, see
basic_rotations.
|
The type alias orientation_qty is provided for basic_orientation_qty<double>.
Member functions
(Constructor)
(Constructor)
|
(1) |
|
(2) |
|
(3) |
|
(4) |
-
(1) Default constructor.
-
(2) Explicit converting constructor from a different floating-point type.
-
(3) Constructs an orientation from a non-zero complex number. Throws
std::domain_errorifstd::abs(cplx)is not a normal number. -
(4) Constructs from an angle.
import ninbot;
using namespace nin;
int main() {
R2::orientation_qty defaulted; // 0°
R2::orientation_qty from_angle { 90_deg }; // 90°
R2::orientation_qty from_complex { std::complex<double>{1,1} }; // 45°
}
to_complex
complex number representation
to_complex
complex number representation
|
(1) |
Returns the representation of the orientation as a std::complex number.
import ninbot;
using namespace nin;
int main() {
R2::orientation_qty ori {90_deg};
std::complex<double> c = ori.to_complex(); // c = 𝑖 ≡ (0, 1)
}
to_angle
angle representation
to_angle
angle representation
|
(1) |
Returns the angle in radians within the half-open interval (centre − π, centre + π] By default the angle is wrapped to (−π, π].
import ninbot;
using namespace nin;
int main() {
R2::orientation_qty ori {270_deg};
units::angle a1 = ori.to_angle(); // a1 = -90°
units::angle a2 = ori.to_angle(180_deg); // a2 = 270°
}
Non-member functions
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) |
|
(2) |
Adds a specialization of std::formatter that formats the
orientation as an angle by delegating to the
units::angle_v formatter.
The <format-spec> syntax is
[<float-spec>] [ "_" <unit> ]
with the following rules:
-
<float-spec>— anything before the first_or the end of the spec 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 (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::orientation_qty ori0;
nin::R2::orientation_qty ori90 {90_deg};
std::println("{}", ori0); // "0 rad"
std::println("{:_deg}", ori90); // "90°"
std::println("{:_}", ori90); // "1.5707963267948966"
std::println("{:.1f_deg}", ori90); // "90.0°"
std::println("{:.2f_rad}", ori90); // "1.57 rad"
}