mt
 All Classes Files Functions Enumerations Groups Pages
Public Member Functions | List of all members
mt::Unit3 Class Reference

Three dimensional unit vector class. More...

#include <unit3.h>

Inheritance diagram for mt::Unit3:
mt::Vector3

Public Member Functions

 Unit3 ()
 Default constructor. Creates [0.0, 0.0, 1.0] vector.
 Unit3 (const Scalar &x, const Scalar &y, const Scalar &z)
 Unit3 (const Scalar *u)
 Constructor for pointer input.
 Unit3 (const Vector3 &v)
 Constructor for Vector3 input.
Unit3operator= (const Vector3 &v)
bool operator== (const Unit3 &u) const
bool operator!= (const Unit3 &u) const
Scalar angleCos (const Unit3 &u) const
 Cosine of the angle between vectors.
Scalar angle (const Unit3 &u) const
 Angle between vectors in the range [0, pi] expressed in radians.
void setValue (const Scalar &x, const Scalar &y, const Scalar &z)
 Sets vector values from three input values.
void setValue (const Scalar *u)
 Sets vector values from pointer input.
- Public Member Functions inherited from mt::Vector3
 Vector3 ()
 Default constructor. Creates a null vector [0.0, 0.0, 0.0].
 Vector3 (const Scalar &x, const Scalar &y, const Scalar &z)
 Constructor for three input values.
 Vector3 (const Scalar *v)
 Constructor for pointer input.
Scalar & operator[] (size_t n)
 Unchecked element access.
const Scalar & operator[] (size_t n) const
 Unchecked element access.
Vector3operator+= (const Vector3 &v)
Vector3operator-= (const Vector3 &v)
Vector3operator*= (const Scalar &s)
 Scalar-vector product.
Vector3operator*= (const Vector3 &v)
 Memberwise product.
Vector3operator/= (const Scalar &s)
 Scalar-vector division.
Vector3operator/= (const Vector3 &v)
 Memberwise division.
bool operator== (const Vector3 &v) const
bool operator!= (const Vector3 &v) const
Scalar sum () const
 Vector element sum.
Scalar dot (const Vector3 &v) const
 Dot product.
Vector3 cross (const Vector3 &v) const
 Cross product.
Scalar length2 () const
 Squared vector length.
Scalar length () const
 Vector length.
Vector3normalize ()
 Normalize vector to unit length.
Scalar distance2 (const Vector3 &v) const
 Squared distance between vectors.
Scalar distance (const Vector3 &v) const
 Distance between vectors.
Scalar angleCos (const Vector3 &v) const
 Cosine of the angle between vectors.
Scalar angleSin (const Vector3 &v) const
 Sine of the angle between vectors.
Scalar angle (const Vector3 &v) const
 Angle between vectors in the range [0, pi] expressed in radians.
size_t minAxis () const
 Index of element with minimum value.
size_t maxAxis () const
 Index of element with maximum value.
size_t furthestAxis () const
 Index of furthest axis.
size_t closestAxis () const
 Index of closest axis.
Scalar min () const
 Minimum value.
Scalar max () const
 Maximum value.
Scalar & at (size_t n)
 Checked element access.
const Scalar & at (size_t n) const
 Checked element access.

Detailed Description

Three dimensional unit vector class.

The Unit3 class provides the usual operators and functions used in vector algebra and manipulation.

The main difference from Vector3, its base class, is that the vector length is always guarranteed to be unity, so for example, a unit vector cannot be initialized with a null vector, and if a vector with length different than unity is assigned to a unit vector, it is scaled to unit length. Also, the comparison criterion used for equality and difference is based only on the angle between the Unit3's instead of both distance and angle for Vector3's. This is an example of how to use the Unit3 class and its differences with the Vector3 class:

// The definition of the used Scalar type is from the scalar.h header of
// this library
using namespace mt;
// Constructors
Unit3 u1; // u1 = [0.0, 0.0, 1.0]
Unit3 u2(2.0, 0.0, 0.0); // u2 = [1.0, 0.0, 0.0]
Vector3 v1; // v1 = [0.0, 0.0, 0.0]
Vector3 v2(2.0, 0.0, 0.0); // v2 = [2.0, 0.0, 0.0]
// Operations
u1 = -2.0 * u2; // u1 = [-1.0, 0.0, 0.0]
u1 = -2.0 * v2; // u1 = [-1.0, 0.0, 0.0]
v1 = -2.0 * v2; // v1 = [-4.0, 0.0, 0.0]
// Orthonormal basis defined by two unit vectors
u1.setValue(1.0, 0.0, 0.0); // u1 = [1.0, 0.0, 0.0]
u2.setValue(1.0, 1.0, 0.0); // u2 = [0.70717, 0.70717, 0.0]
Unit3 onbase2;
Unit3 onbase3;
orthonormalBasis(u1, u2, onbase2, onbase3);
// Orthonormal basis is given by unit vectors {u1, onbase2, onbase3}
// u1 = [1.0, 0.0, 0.0]
// onbase2 = [0.0, 1.0, 0.0]
// onbase3 = [0.0, 0.0, 1.0]

Constructor & Destructor Documentation

mt::Unit3::Unit3 ( const Scalar &  x,
const Scalar &  y,
const Scalar &  z 
)
inline

Constructor for three input values.

The input values need not define a vector of unit length, since a vector is constructed and then normalized.

Member Function Documentation

Unit3 & mt::Unit3::operator= ( const Vector3 v)
inline

Assignment operator.

Parameters
vThe Vector3 to assign to this object.
Returns
A reference to this object.
bool mt::Unit3::operator== ( const Unit3 u) const
inline

Equality operator. The comparison criterion is that the angle between the two vectors must be equal to zero.


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