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>.

Nested types

Type Definition

value_type

T

Member functions

(Constructor)

basic_orientation_qty()

(1)

explicit basic_orientation_qty(basic_orientation_qty<Tin> other)

(2)

basic_orientation_qty(std::complex<Tin> cplx)

(3)

basic_orientation_qty(units::angle_v<T> angle)

(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_error if std::abs(cplx) is not a normal number.

  • (4) Constructs from an angle.

Example
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

std::complex<T> const& to_complex()

(1)

Returns the representation of the orientation as a std::complex number.

Example
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

units::angle to_angle(units::angle centre = 0_rad)

(1)

Returns the angle in radians within the half-open interval (centreπ, centre + π] By default the angle is wrapped to (−π, π].

Example
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::format("{:<format-spec>}", ori)

(1)

std::print("{<format-spec>}", ori)

(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 after selects the unit used for the displayed value and the trailing unit label (e.g. _rad, _deg). The literal deg is rendered as a degree sign ° without a leading space; every other unit is rendered with a leading space (e.g. ` rad`). When the is omitted, the default unit label ` rad` is appended.

Example
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"
}