Simbody  3.6
SimTK::UnitVec< P, S > Class Template Reference

This class is a Vec3 plus an ironclad guarantee either that: More...

Public Types

typedef Vec< 3, P, S > BaseVec
 
typedef UnitRow< P, S > TransposeType
 

Public Member Functions

 UnitVec ()
 Default constructor initializes to all-NaN even in Release mode so that we maintain the above-promised contract. More...
 
 UnitVec (const UnitVec &u)
 Copy constructor does not require normalization since we know the source is a unit vector. More...
 
template<int S2>
 UnitVec (const UnitVec< P, S2 > &u)
 Automatic conversion from UnitVec with different stride; no computation required. More...
 
 UnitVec (const BaseVec &v)
 Explicit conversion from Vec to UnitVec, requiring expensive normalization. More...
 
template<int S2>
 UnitVec (const Vec< 3, P, S2 > &v)
 Explicit conversion from Vec of any stride to this UnitVec, requiring expensive normalization. More...
 
 UnitVec (const P &x, const P &y, const P &z)
 Create a unit vector in the direction of the vector (x,y,z) whose measure numbers are supplied – this requires an expensive normalization since we don't know that the supplied vector is normalized. More...
 
 UnitVec (const CoordinateAxis &axis)
 Implicit conversion from a coordinate axis XAxis, YAxis, or ZAxis to a UnitVec3. Does not require any computation. More...
 
 UnitVec (const CoordinateDirection &dir)
 Implicit conversion from a coordinate axis direction to a UnitVec3. The axis direction is given by one of XAxis, YAxis, ZAxis or NegXAxis, NegYAxis, NegZAxis. Does not require any computation. More...
 
 UnitVec (int axis)
 Construct a unit axis vector 100 010 001 given 0,1, or 2; this is not an implicit conversion. More...
 
UnitVecoperator= (const UnitVec &u)
 Copy assignment does not require normalization. More...
 
template<int S2>
UnitVecoperator= (const UnitVec< P, S2 > &u)
 Copy assignment from a UnitVec whose stride differs from this one; no normalization required. More...
 
const BaseVecasVec3 () const
 Return a reference to the underlying Vec3 (no copying here). More...
 
UnitVec< P, 1 > negate () const
 Returns a new unit vector pointing in the opposite direction from this one; does not modify this UnitVec object. More...
 
UnitVec< P, 1 > operator- () const
 Returns a new unit vector pointing in the opposite direction from this one. More...
 
const TransposeTypeoperator~ () const
 Return a const reference to this unit vector re-expressed as a unit row; no computational cost. More...
 
TransposeTypeoperator~ ()
 Return a writable reference to this unit vector re-expressed as a unit row; no computational cost. More...
 
const P & operator[] (int i) const
 Return one element of this unit vector as a const reference; there is no corresponding writable index function since changing a single element of a unit vector would violate the contract that it has unit length at all times. More...
 
const P & operator() (int i) const
 Return one element of this unit vector as a const reference; there is no corresponding writable index function since changing a single element of a unit vector would violate the contract that it has unit length at all times. More...
 
UnitVec< P, 1 > abs () const
 Return a new unit vector whose measure numbers are the absolute values of the ones here. More...
 
UnitVec< P, 1 > perp () const
 Return a new unit vector perpendicular to this one but otherwise arbitrary. More...
 
 UnitVec (const BaseVec &v, bool)
 (Advanced) This constructor is only for our friends whom we trust to give us an already-normalized vector which we simply accept as normalized without checking. More...
 
template<int S2>
 UnitVec (const Vec< 3, P, S2 > &v, bool)
 (Advanced) This constructor is only for our friends whom we trust to give us an already-normalized vector which we simply accept as normalized without checking (this version accepts an input vector of any stride). More...
 

Static Public Member Functions

static const UnitVecgetAs (const P *p)
 (Advanced) Reinterpret a given memory location as a UnitVec like this one, without checking – don't use this if you aren't absolutely certain that the memory location actually does contain a unit vector, with the correct stride! This overrides the base Vec class method of the same name. More...
 

Related Functions

(Note that these are not member functions.)

template<class P , int S1, int S2>
bool operator== (const UnitVec< P, S1 > &u1, const UnitVec< P, S2 > &u2)
 Compare two UnitVec3 objects for exact, bitwise equality (not very useful). More...
 
template<class P , int S1, int S2>
bool operator!= (const UnitVec< P, S1 > &u1, const UnitVec< P, S2 > &u2)
 Compare two UnitVec3 objects and return true unless they are exactly bitwise equal (not very useful). More...
 

Detailed Description

template<class P, int S>
class SimTK::UnitVec< P, S >

This class is a Vec3 plus an ironclad guarantee either that:

  • the length is one (to within a very small tolerance), or
  • all components are NaN.

Member Typedef Documentation

◆ BaseVec

template<class P , int S>
typedef Vec<3,P,S> SimTK::UnitVec< P, S >::BaseVec

◆ TransposeType

template<class P , int S>
typedef UnitRow<P,S> SimTK::UnitVec< P, S >::TransposeType

Constructor & Destructor Documentation

◆ UnitVec() [1/11]

template<class P , int S>
SimTK::UnitVec< P, S >::UnitVec ( )
inline

Default constructor initializes to all-NaN even in Release mode so that we maintain the above-promised contract.

◆ UnitVec() [2/11]

template<class P , int S>
SimTK::UnitVec< P, S >::UnitVec ( const UnitVec< P, S > &  u)
inline

Copy constructor does not require normalization since we know the source is a unit vector.

◆ UnitVec() [3/11]

template<class P , int S>
template<int S2>
SimTK::UnitVec< P, S >::UnitVec ( const UnitVec< P, S2 > &  u)
inline

Automatic conversion from UnitVec with different stride; no computation required.

◆ UnitVec() [4/11]

template<class P , int S>
SimTK::UnitVec< P, S >::UnitVec ( const BaseVec v)
inlineexplicit

Explicit conversion from Vec to UnitVec, requiring expensive normalization.

◆ UnitVec() [5/11]

template<class P , int S>
template<int S2>
SimTK::UnitVec< P, S >::UnitVec ( const Vec< 3, P, S2 > &  v)
inlineexplicit

Explicit conversion from Vec of any stride to this UnitVec, requiring expensive normalization.

◆ UnitVec() [6/11]

template<class P , int S>
SimTK::UnitVec< P, S >::UnitVec ( const P &  x,
const P &  y,
const P &  z 
)
inline

Create a unit vector in the direction of the vector (x,y,z) whose measure numbers are supplied – this requires an expensive normalization since we don't know that the supplied vector is normalized.

◆ UnitVec() [7/11]

template<class P , int S>
SimTK::UnitVec< P, S >::UnitVec ( const CoordinateAxis axis)
inline

Implicit conversion from a coordinate axis XAxis, YAxis, or ZAxis to a UnitVec3. Does not require any computation.

◆ UnitVec() [8/11]

template<class P , int S>
SimTK::UnitVec< P, S >::UnitVec ( const CoordinateDirection dir)
inline

Implicit conversion from a coordinate axis direction to a UnitVec3. The axis direction is given by one of XAxis, YAxis, ZAxis or NegXAxis, NegYAxis, NegZAxis. Does not require any computation.

◆ UnitVec() [9/11]

template<class P , int S>
SimTK::UnitVec< P, S >::UnitVec ( int  axis)
inlineexplicit

Construct a unit axis vector 100 010 001 given 0,1, or 2; this is not an implicit conversion.

◆ UnitVec() [10/11]

template<class P , int S>
SimTK::UnitVec< P, S >::UnitVec ( const BaseVec v,
bool   
)
inline

(Advanced) This constructor is only for our friends whom we trust to give us an already-normalized vector which we simply accept as normalized without checking.

◆ UnitVec() [11/11]

template<class P , int S>
template<int S2>
SimTK::UnitVec< P, S >::UnitVec ( const Vec< 3, P, S2 > &  v,
bool   
)
inline

(Advanced) This constructor is only for our friends whom we trust to give us an already-normalized vector which we simply accept as normalized without checking (this version accepts an input vector of any stride).

Member Function Documentation

◆ operator=() [1/2]

template<class P , int S>
UnitVec& SimTK::UnitVec< P, S >::operator= ( const UnitVec< P, S > &  u)
inline

Copy assignment does not require normalization.

◆ operator=() [2/2]

template<class P , int S>
template<int S2>
UnitVec& SimTK::UnitVec< P, S >::operator= ( const UnitVec< P, S2 > &  u)
inline

Copy assignment from a UnitVec whose stride differs from this one; no normalization required.

◆ asVec3()

template<class P , int S>
const BaseVec& SimTK::UnitVec< P, S >::asVec3 ( ) const
inline

Return a reference to the underlying Vec3 (no copying here).

◆ negate()

template<class P , int S>
UnitVec<P,1> SimTK::UnitVec< P, S >::negate ( ) const
inline

Returns a new unit vector pointing in the opposite direction from this one; does not modify this UnitVec object.

Cost is 3 flops.

◆ operator-()

template<class P , int S>
UnitVec<P,1> SimTK::UnitVec< P, S >::operator- ( ) const
inline

Returns a new unit vector pointing in the opposite direction from this one.

Cost is 3 flops.

◆ operator~() [1/2]

template<class P , int S>
const TransposeType& SimTK::UnitVec< P, S >::operator~ ( ) const
inline

Return a const reference to this unit vector re-expressed as a unit row; no computational cost.

◆ operator~() [2/2]

template<class P , int S>
TransposeType& SimTK::UnitVec< P, S >::operator~ ( )
inline

Return a writable reference to this unit vector re-expressed as a unit row; no computational cost.

◆ operator[]()

template<class P , int S>
const P& SimTK::UnitVec< P, S >::operator[] ( int  i) const
inline

Return one element of this unit vector as a const reference; there is no corresponding writable index function since changing a single element of a unit vector would violate the contract that it has unit length at all times.

◆ operator()()

template<class P , int S>
const P& SimTK::UnitVec< P, S >::operator() ( int  i) const
inline

Return one element of this unit vector as a const reference; there is no corresponding writable index function since changing a single element of a unit vector would violate the contract that it has unit length at all times.

◆ abs()

template<class P , int S>
UnitVec<P,1> SimTK::UnitVec< P, S >::abs ( ) const
inline

Return a new unit vector whose measure numbers are the absolute values of the ones here.

This will still have unit length but will be a reflection of this unit vector into the first octant (+x,+y,+z). Note that we are returning the packed form of UnitVec regardless of our stride here.

◆ perp()

template<class P , int S>
UnitVec< P, 1 > SimTK::UnitVec< P, S >::perp
inline

Return a new unit vector perpendicular to this one but otherwise arbitrary.

Some care is taken to ensure good numerical conditioning for the result regardless of what goes in. Cost is about 50 flops.

◆ getAs()

template<class P , int S>
static const UnitVec& SimTK::UnitVec< P, S >::getAs ( const P *  p)
inlinestatic

(Advanced) Reinterpret a given memory location as a UnitVec like this one, without checking – don't use this if you aren't absolutely certain that the memory location actually does contain a unit vector, with the correct stride! This overrides the base Vec class method of the same name.

Friends And Related Function Documentation

◆ operator==()

template<class P , int S1, int S2>
bool operator== ( const UnitVec< P, S1 > &  u1,
const UnitVec< P, S2 > &  u2 
)
related

Compare two UnitVec3 objects for exact, bitwise equality (not very useful).

◆ operator!=()

template<class P , int S1, int S2>
bool operator!= ( const UnitVec< P, S1 > &  u1,
const UnitVec< P, S2 > &  u2 
)
related

Compare two UnitVec3 objects and return true unless they are exactly bitwise equal (not very useful).


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