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

Three-dimensional vector class. More...

#include <vector3.h>

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

Public Member Functions

 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.
void setValue (const Scalar &x, const Scalar &y, const Scalar &z)
 Sets vector values from three input values.
void setValue (const Scalar *v)
 Sets vector values from pointer input.

Friends

class Quaternion

Detailed Description

Three-dimensional vector class.

The Vector3 class provides the usual operators and functions used in vector algebra and manipulation. The type of a vector element is Scalar, so in order to use the class, the type name must exist either as a class or a typedef.

This is an example of how to use the Vector3 class:

// The definition of the used Scalar type is from the scalar.h header of
// this library
using namespace mt;
// Constructors and some basic operators
Vector3 v1(1.0, 0.0, -2.5); // three-value constructor
Vector3 v2; // default constructor, creates null vector
v2 = 2.0 * v1; // v2 = [2.0, 0.0, -5.0]
Vector3 v3 = v1 + v2; // v3 = [3.0, 0.0, -7.5]
// Some vector operations
Scalar s1 = dot(v2, v2); // s1 = 29.0
v1.setValue(2.0, 0.0, 0.0); // v1 = [2.0, 0.0, 0.0]
v2.setValue(0.0, 0.0, 1.0); // v2 = [0.0, 0.0, 1.0]
v3 = cross(v1, v2); // v3 = [0.0, -2.0, 0.0]
s1 = distance(v1, v2); // s1 = 2.23607
s1 = radToDeg(angle(v1, v2)); // s1 = 90 degrees
v1 = normalize(v3); // v1 = [0.0, -1.0, 0.0], v3 = [0.0, -2.0, 0.0] v3 remains the same
v3.normalize(); // v3 = [0.0, -1.0, 0.0] v3 has changed

Member Function Documentation

bool mt::Vector3::operator== ( const Vector3 v) const
inline

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


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