Simbody
Public Types | Public Member Functions | Related Functions

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

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

More...

#include <UnitVec.h>

Inheritance diagram for SimTK::UnitVec< P, S >:

List of all members.

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.
 UnitVec (const UnitVec &u)
 Copy constructor does not require normalization since we know the source is a unit vector.
template<int S2>
 UnitVec (const UnitVec< P, S2 > &u)
 Automatic conversion from UnitVec with different stride; no computation required.
 UnitVec (const BaseVec &v)
 Explicit conversion from Vec to UnitVec, requiring expensive normalization.
template<int S2>
 UnitVec (const Vec< 3, P, S2 > &v)
 Explicit conversion from Vec of any stride to this UnitVec, requiring expensive normalization.
 UnitVec (const RealP &x, const RealP &y, const RealP &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.
 UnitVec (const CoordinateAxis &axis)
 Implicit conversion from a coordinate axis XAxis, YAxis, or ZAxis to a UnitVec3. Does not require any computation.
 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.
 UnitVec (int axis)
 Construct a unit axis vector 100 010 001 given 0,1, or 2; this is not an implicit conversion.
UnitVecoperator= (const UnitVec &u)
 Copy assignment does not require normalization.
template<int S2>
UnitVecoperator= (const UnitVec< P, S2 > &u)
 Copy assignment from a UnitVec whose stride differs from this one; no normalization required.
const BaseVecasVec3 () const
 Return a reference to the underlying Vec3 (no copying here).
UnitVec< P, 1 > negate () const
 Returns a new unit vector pointing in the opposite direction from this one; does not modify this UnitVec object.
UnitVec< P, 1 > operator- () const
 Returns a new unit vector pointing in the opposite direction from this one.
const TransposeTypeoperator~ () const
 Return a const reference to this unit vector re-expressed as a unit row; no computational cost.
TransposeTypeoperator~ ()
 Return a writable reference to this unit vector re-expressed as a unit row; no computational cost.
const RealP & 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.
const RealP & 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.
UnitVec< P, 1 > abs () const
 Return a new unit vector whose measure numbers are the absolute values of the ones here.
UnitVec< P, 1 > perp () const
 Return a new unit vector perpendicular to this one but otherwise arbitrary.
 UnitVec (const BaseVec &v, bool)
 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.
template<int S2>
 UnitVec (const Vec< 3, RealP, S2 > &v, bool)
 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).

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

Detailed Description

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

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


Member Typedef Documentation

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

Constructor & Destructor Documentation

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.

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.

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.

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

Explicit conversion from Vec to UnitVec, requiring expensive normalization.

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

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

template<class P, int S>
SimTK::UnitVec< P, S >::UnitVec ( const RealP &  x,
const RealP &  y,
const RealP &  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.

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.

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.

template<class P, int S>
SimTK::UnitVec< P, S >::UnitVec ( int  axis) [inline, explicit]

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

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

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.

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

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

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

Copy assignment does not require normalization.

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.

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

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

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.

Reimplemented from SimTK::Vec< 3, P, S >.

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.

Reimplemented from SimTK::Vec< 3, P, S >.

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.

Reimplemented from SimTK::Vec< 3, P, S >.

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.

Reimplemented from SimTK::Vec< 3, P, S >.

template<class P, int S>
const RealP& 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.

Reimplemented from SimTK::Vec< 3, P, S >.

template<class P, int S>
const RealP& 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.

Reimplemented from SimTK::Vec< 3, P, S >.

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.

Reimplemented from SimTK::Vec< 3, P, S >.

template<class P , int S>
UnitVec< P, 1 > SimTK::UnitVec< P, S >::perp ( ) const [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.


Friends And Related Function Documentation

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

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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines