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

Nested types

Type Definition

value_type

T

orientation_qty

basic_orientation_qty<T>

Member functions

(Constructor)

basic_rotation()

(1)

basic_rotation(copy)

(2)

basic_rotation(angle)

(3)

basic_rotation(reference, target, revolutions = 0)

(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 reference onto measure (both of type R2::orientation_qty), plus an optional integer number of full revolutions.

Example
import ninbot;
using namespace nin;
int main() {
    R2::rotation rot0;        // 0°
    R2::rotation rot1 { 720_deg };
}

invert

inverts the rotation

basic_rotation & invert()

(1)

Inverts the rotation in place. Returns a reference to *this to allow chaining.

Example
import ninbot;
using namespace nin;
int main() {
    R2::rotation rot { 20_deg };
    rot.invert();     // rot is now -20°
}

angle

rotation angle

units::angle_v<T> angle() const

(1)

units::angle_v<T> & angle()

(2)

Example
import ninbot;
using namespace nin;
int main() {
    R2::rotation rot { 45_deg };
    rot.angle() += 90_deg;     // rot is now 135°
}

operator()

applies the rotation

Container2 operator () (vec)

(1)

orientation_qty operator () (orientation)

(2)

basic_position_qty operator () (point)

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

Example
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

basic_rotation inv(rotation)

(1)

Returns the inverse of the argument rotation, of type R2::basic_rotation.

Example
import ninbot;
using namespace nin;
int main() {
    R2::rotation rot  { 75_deg };
    R2::rotation roti = inv(rot);     // roti = -75°
}

compose

composes two rotations

basic_rotation compose(lhs, rhs)

(1)

returns the composition of lhs with rhs. Both lhs and rhs are of type R2::basic_rotation.

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

(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 after selects the unit used for the displayed value and the trailing unit label. Must be dimensionally compatible with units::angle_v<T> (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::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°"
}