Motive Animation System
An open source project by FPL.
 All Classes Functions Variables Typedefs Friends Pages
motive::Angle Class Reference

Represent an angle in radians, uniquely in the range (-pi, pi]. More...

#include <angle.h>

Detailed Description

Represent an angle in radians, uniquely in the range (-pi, pi].

We include pi in the range, but exclude -pi, because pi and -pi are equivalent mod 2pi.

Equivalence is key to this class. We want only one representation of every equivalent angle. For example, 0 and 2pi are both represented as 0, internally. This unique representation allows for comparison and precise arithmetic.

All operators keep the angle values in the valid range.

Why use instead of Quaternions?

Quaternions are great for three dimensional rotations, but for many applications you only have two dimensional rotations. Instead of the four floats and heavy operations required by quaternions, an angle can represent the rotation in one float and reasonably light operations. Angles are easier to do trigonometry on. Also, they're conceptually simpler.

Public Member Functions

 Angle (float angle)
 
Angle Abs () const
 Returns the absolute value of an angle.
 
Angleoperator= (const Angle &rhs)
 
Angleoperator+= (const Angle &rhs)
 Add rhs and ensure result is in the range (-pi,pi].
 
Angleoperator-= (const Angle &rhs)
 Subtract rhs and ensure result is in the range (-pi,pi].
 
Angleoperator*= (const float rhs)
 Multiply rhs and ensure result is in the normalized range (-pi,pi].
 
Angleoperator/= (const float rhs)
 Divide rhs and ensure result is in the normalized range (-pi,pi].
 
Angle operator- () const
 Negate the angle and ensure result is in the normalized range (-pi,pi].
 
float ToRadians () const
 Return the angle value in radians. Value is in the range (-pi,pi].
 
float ToDegrees () const
 Return the angle value in degrees. Value is in the range (-180,180].
 
mathfu::vec3 ToVectorSystem (const AngleToVectorSystem system) const
 
mathfu::vec3 ToXYVector () const
 
mathfu::vec2 ToXYVector2f () const
 
mathfu::vec3 ToXZVector () const
 
mathfu::vec3 ToYZVector () const
 
mathfu::vec3 ToYXVector () const
 
mathfu::vec2 ToYXVector2f () const
 
mathfu::vec3 ToZXVector () const
 
mathfu::vec3 ToZYVector () const
 
mathfu::mat3 ToRotationMatrix (const AngleToVectorSystem system) const
 
mathfu::mat3 ToXYRotationMatrix () const
 Returns a matrix that rotates about the Z axis angle radians.
 
mathfu::mat3 ToXZRotationMatrix () const
 Returns a matrix that rotates about the Y axis angle radians.
 
mathfu::mat3 ToYZRotationMatrix () const
 Returns a matrix that rotates about the X axis angle radians.
 
mathfu::mat3 ToYXRotationMatrix () const
 Returns a matrix that rotates about the Z axis -angle radians.
 
mathfu::mat3 ToZXRotationMatrix () const
 Returns a matrix that rotates about the Y axis -angle radians.
 
mathfu::mat3 ToZYRotationMatrix () const
 Returns a matrix that rotates about the X axis -angle radians.
 
bool IsValid () const
 
Angle Clamp (const Angle &center, const Angle &max_diff) const
 

Static Public Member Functions

static float WrapAngle (float angle)
 
static Angle FromWithinThreePi (const float angle)
 
static Angle FromRadians (const float radians)
 Create from radians, which is converted to the range (-pi, pi].
 
static Angle FromDegrees (const float degrees)
 Create from degrees, which is converted to the range (-pi, pi].
 
static Angle FromVectorSystem (const mathfu::vec3 &v, const AngleToVectorSystem system)
 
static Angle FromXYVector (const mathfu::vec3 &v)
 
static Angle FromXZVector (const mathfu::vec3 &v)
 
static Angle FromYZVector (const mathfu::vec3 &v)
 
static Angle FromYXVector (const mathfu::vec3 &v)
 
static Angle FromZXVector (const mathfu::vec3 &v)
 
static Angle FromZYVector (const mathfu::vec3 &v)
 
static bool IsAngleInRange (const float angle)
 

Friends

bool operator== (const Angle &a, const Angle &b)
 
bool operator< (const Angle &a, const Angle &b)
 
bool operator<= (const Angle &a, const Angle &b)
 

Constructor & Destructor Documentation

motive::Angle::Angle ( float  angle)
inlineexplicit

Create from angle, which is already in the valid range (-pi,pi]. If your angle is outside that range, construct the Angle with the slower FromRadians function to automatically wrap it.

Parameters
angleradians in the range (-pi,pi] – i.e. exclusive of -pi but inclusive of +pi.

Member Function Documentation

Angle motive::Angle::Clamp ( const Angle center,
const Angle max_diff 
) const
inline

Clamps the angle to the range [center - max_diff, center + max_diff]. max_diff must be in the range [0~pi].

static Angle motive::Angle::FromVectorSystem ( const mathfu::vec3 &  v,
const AngleToVectorSystem  system 
)
inlinestatic

Returns a point on the unit circle corresponding to a sweep of angle across the specified vector system.

static Angle motive::Angle::FromWithinThreePi ( const float  angle)
inlinestatic

Create from angle, in radians, which is in the range (-3pi,3pi]. This function is significantly faster than WrapAngle since it avoids division. It's also more precise for the same reason. The range may seem strange at first glance; it's a consequence of the implementation. Just know that any two sums of normalized angles will still be in the range (-3pi,3pi].

static Angle motive::Angle::FromXYVector ( const mathfu::vec3 &  v)
inlinestatic

Create from the x,y coordinates of a vector, using the system described in ToXYVector().

static Angle motive::Angle::FromXZVector ( const mathfu::vec3 &  v)
inlinestatic

Create from the x,z coordinates of a vector, using the system described in ToXZVector().

static Angle motive::Angle::FromYXVector ( const mathfu::vec3 &  v)
inlinestatic

Create from the y,x coordinates of a vector, using the system described in ToYXVector().

static Angle motive::Angle::FromYZVector ( const mathfu::vec3 &  v)
inlinestatic

Create from the y,z coordinates of a vector, using the system described in ToYZVector().

static Angle motive::Angle::FromZXVector ( const mathfu::vec3 &  v)
inlinestatic

Create from the z,x coordinates of a vector, using the system described in ToZXVector().

static Angle motive::Angle::FromZYVector ( const mathfu::vec3 &  v)
inlinestatic

Create from the z,y coordinates of a vector, using the system described in ToZYVector().

static bool motive::Angle::IsAngleInRange ( const float  angle)
inlinestatic

Return true if 'angle' is within the valid range (-pi,pi], that is, the range inclusive of +pi but exclusive of -pi.

bool motive::Angle::IsValid ( ) const
inline

Check internal consistency. If class is functioning correctly, should always return true.

mathfu::mat3 motive::Angle::ToRotationMatrix ( const AngleToVectorSystem  system) const
inline

Returns a point on the unit circle corresponding to a sweep of angle across the specified vector system.

mathfu::vec3 motive::Angle::ToVectorSystem ( const AngleToVectorSystem  system) const
inline

Returns a point on the unit circle corresponding to a sweep of angle across the specified vector system.

mathfu::vec3 motive::Angle::ToXYVector ( ) const
inline

Returns a point on unit circle corresponding to a sweep of angle degrees from the x-axis towards the y-axis. 0 ==> ( 1, 0, 0) pi/2 ==> ( 0, 1, 0) pi ==> (-1, 0, 0) 3pi/2 ==> ( 0, -1, 0)

mathfu::vec2 motive::Angle::ToXYVector2f ( ) const
inline

Returns a point on unit circle corresponding to a sweep of angle degrees from the x-axis towards the y-axis. 0 ==> ( 1, 0 ) pi/2 ==> ( 0, 1 ) pi ==> (-1, 0 ) 3pi/2 ==> ( 0, -1 )

mathfu::vec3 motive::Angle::ToXZVector ( ) const
inline

Returns a point on unit circle corresponding to a sweep of angle degrees from the x-axis towards the z-axis. 0 ==> ( 1, 0, 0) pi/2 ==> ( 0, 0, 1) pi ==> (-1, 0, 0) 3pi/2 ==> ( 0, 0, -1)

mathfu::vec3 motive::Angle::ToYXVector ( ) const
inline

Returns a point on unit circle corresponding to a sweep of angle degrees from the y-axis towards the x-axis. 0 ==> ( 0, 1, 0) pi/2 ==> ( 1, 0, 0) pi ==> ( 0, -1, 0) 3pi/2 ==> (-1, 0, 0)

mathfu::vec2 motive::Angle::ToYXVector2f ( ) const
inline

Returns a point on unit circle corresponding to a sweep of angle degrees from the y-axis towards the x-axis. 0 ==> ( 0, 1 ) pi/2 ==> ( 1, 0 ) pi ==> ( 0, -1 ) 3pi/2 ==> (-1, 0 )

mathfu::vec3 motive::Angle::ToYZVector ( ) const
inline

Returns a point on unit circle corresponding to a sweep of angle degrees from the y-axis towards the z-axis. 0 ==> (0, 1, 0) pi/2 ==> (0, 0, 1) pi ==> (0, -1, 0) 3pi/2 ==> (0, 0, -1)

mathfu::vec3 motive::Angle::ToZXVector ( ) const
inline

Returns a point on unit circle corresponding to a sweep of angle degrees from the z-axis towards the x-axis. 0 ==> ( 0, 0, 1) pi/2 ==> ( 1, 0, 0) pi ==> ( 0, 0, -1) 3pi/2 ==> (-1, 0, 0)

mathfu::vec3 motive::Angle::ToZYVector ( ) const
inline

Returns a point on unit circle corresponding to a sweep of angle degrees from the z-axis towards the y-axis. 0 ==> (0, 0, 1) pi/2 ==> (0, 1, 0) pi ==> (0, 0, -1) 3pi/2 ==> (0, -1, 0)

static float motive::Angle::WrapAngle ( float  angle)
inlinestatic

Wraps an angle to the range (-pi, pi]. This function is slow because it has a division. When possible, use FromWithinThreePi instead.


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