Brick
Loading...
Searching...
No Matches
Rotation2d Class Reference

#include <rotation2d.h>

Description

Class representing a rotation in 2d space. Stores cos and sin, and computes angles based on that.

By nature the stored angle is wrapped, but there are functions that return angles wrapped specifically between e.g. [-180, 180) and [0, 360)

If you need your angle to be continuous use units::Angle instead.

Public Member Functions

constexpr Rotation2d ()=default
 Default Constructor for Rotation2d.
constexpr Rotation2d (units::Angle value)
 Constructs a rotation given a units::Angle.
constexpr Rotation2d (double value)
 Constructs a rotation given an angle in radians.
constexpr Rotation2d (double x, double y)
constexpr Rotation2d (units::Length x, units::Length y)
constexpr units::Angle angle () const
 Gets an Angle equal to this rotation.
constexpr double angle (units::Angle unit) const
 Gets the angle in the supplied unit.
constexpr double radians () const
 Gets the rotation in radians.
constexpr double degrees () const
 Gets the rotation in degrees.
constexpr double revolutions () const
 Gets the rotation in revolutions.
constexpr double gradians () const
 Gets the rotation in gradians.
constexpr double f_cos () const
 Gets the cosine of the rotation.
constexpr double f_sin () const
 Gets the sine of the rotation.
constexpr double f_tan () const
 Gets the tangent of the rotation.
constexpr Rotation2d inverse () const
 Inverts this rotation (conjugate).
constexpr Rotation2d opposite () const
 Flips this rotation across the origin.
constexpr EMat< 2, 2 > rotation_matrix () const
 Gets the rotation matrix corresponding to this rotation.
constexpr double wrapped_radians_180 () const
 Gets the value of this rotation in radians from [-pi, pi].
constexpr double wrapped_degrees_180 () const
 Gets the value of this rotation in degrees from [-180, 180].
constexpr double wrapped_revolutions_180 () const
 Gets the value of this rotation in revolutions from [-0.5, 0.5].
constexpr double wrapped_gradians_180 () const
 Gets the value of this rotation in gradians from [-200, 200].
constexpr double wrapped_radians_360 () const
 Gets the value of this rotation in radians from [0, 2pi).
constexpr double wrapped_degrees_360 () const
 Gets the value of this rotation in degrees from [0, 360).
constexpr double wrapped_revolutions_360 () const
 Gets the value of this rotation in revolutions from [0, 1).
constexpr double wrapped_gradians_360 () const
 Gets the value of this rotation in gradians from [0, 400).
constexpr Rotation2d operator+ (Rotation2d other) const
 Adds another rotation to this rotation.
constexpr Rotation2d & operator+= (Rotation2d other)
 Adds another rotation to this rotation.
constexpr Rotation2d operator- (Rotation2d other) const
 Subtracts another rotation from this rotation.
constexpr Rotation2d & operator-= (Rotation2d other)
 Subtracts another rotation from this rotation.
constexpr Rotation2d operator- () const
 Inverts this rotation (conjugate).
constexpr Rotation2d operator* (double scalar) const
 Multiplies this rotation by a scalar.
constexpr Rotation2d & operator*= (double scalar)
 Multiplies this rotation by a scalar.
constexpr Rotation2d operator/ (double scalar) const
 Divides this rotation by a scalar.
constexpr Rotation2d & operator/= (double scalar)
 Divides this rotation by a scalar.
constexpr bool operator== (Rotation2d other) const
 Checks exact equality between this rotation and another rotation.
constexpr bool is_near (Rotation2d other, units::Angle tolerance=units::Angle(1e-6)) const
 Compares two angles with a default tolerance of 1e-6 radians.

Static Public Member Functions

static constexpr double deg2rad (double deg)
static constexpr double rad2deg (double rad)
static constexpr double wrap_radians_180 (double angle)
static constexpr double wrap_degrees_180 (double angle)
static constexpr double wrap_revolutions_180 (double angle)
static constexpr double wrap_gradians_180 (double angle)
static constexpr double wrap_radians_360 (double angle)
static constexpr double wrap_degrees_360 (double angle)
static constexpr double wrap_revolutions_360 (double angle)
static constexpr double wrap_gradians_360 (double angle)

Friends

constexpr Rotation2d operator* (double scalar, Rotation2d rotation)
 Multiplies a scalar by this rotation.

Constructor & Destructor Documentation

◆ Rotation2d() [1/2]

Rotation2d::Rotation2d ( double x,
double y )
inlineconstexpr

Constructs a rotation given x and y values, as the angle from the x axis to the point.

[theta] = [atan2(y, x)]

Parameters
xThe x value of the point.
yThe y value of the point.

◆ Rotation2d() [2/2]

Rotation2d::Rotation2d ( units::Length x,
units::Length y )
inlineconstexpr

Constructs a rotation given x and y values, as the angle from the x axis to the point.

[theta] = [atan2(y, x)]

Parameters
xThe x value of the point.
yThe y value of the point.

Member Function Documentation

◆ deg2rad()

constexpr double Rotation2d::deg2rad ( double deg)
inlinestaticconstexpr

Helper function that converts degrees to radians.

Parameters
degangle degrees
Returns
double angle radians.

◆ rad2deg()

constexpr double Rotation2d::rad2deg ( double rad)
inlinestaticconstexpr

Helper function that converts radians to degrees.

Parameters
degangle in radians
Returns
double angle in degrees.

◆ wrap_degrees_180()

constexpr double Rotation2d::wrap_degrees_180 ( double angle)
inlinestaticconstexpr

Helper function that wraps an angle in degrees from [-180, 180].

Parameters
angleThe angle to wrap.
Returns
The wrapped angle.

◆ wrap_degrees_360()

constexpr double Rotation2d::wrap_degrees_360 ( double angle)
inlinestaticconstexpr

Helper function that wraps an angle in degrees from [0, 360).

Parameters
angleThe angle to wrap.
Returns
The wrapped angle.

◆ wrap_gradians_180()

constexpr double Rotation2d::wrap_gradians_180 ( double angle)
inlinestaticconstexpr

Helper function that wraps an angle in gradians from [-200, 200].

Parameters
angleThe angle to wrap.
Returns
The wrapped angle.

◆ wrap_gradians_360()

constexpr double Rotation2d::wrap_gradians_360 ( double angle)
inlinestaticconstexpr

Helper function that wraps an angle in gradians from [0, 400).

Parameters
angleThe angle to wrap.
Returns
The wrapped angle.

◆ wrap_radians_180()

constexpr double Rotation2d::wrap_radians_180 ( double angle)
inlinestaticconstexpr

Helper function that wraps an angle in radians from [-pi, pi].

Parameters
angleThe angle to wrap.
Returns
The wrapped angle.

◆ wrap_radians_360()

constexpr double Rotation2d::wrap_radians_360 ( double angle)
inlinestaticconstexpr

Helper function that wraps an angle in radians from [0, 2pi).

Parameters
angleThe angle to wrap.
Returns
The wrapped angle.

◆ wrap_revolutions_180()

constexpr double Rotation2d::wrap_revolutions_180 ( double angle)
inlinestaticconstexpr

Helper function that wraps an angle in revolutions from [-0.5, 0.5].

Parameters
angleThe angle to wrap.
Returns
The wrapped angle.

◆ wrap_revolutions_360()

constexpr double Rotation2d::wrap_revolutions_360 ( double angle)
inlinestaticconstexpr

Helper function that wraps an angle in revolutions from [0, 1).

Parameters
angleThe angle to wrap.
Returns
The wrapped angle.

The documentation for this class was generated from the following file: