A 3D Dynamic Geometry Software

Calques 3D C++



vector Class Reference

Collaboration diagram for vector:

Collaboration graph

List of all members.


Detailed Description

A vector class.

The vector class incapsulates a classic C++ vector of three real values and treats them as a 3 dimensional mathematical vectors.

The most common operations between mathematical vectors (and some which involves scalars too) are defined.


Public Member Functions

 vector ()
 default constructor
 vector (const real &x, const real &y, const real &z)
 constructs a vector from three values
 vector (vector &from, vector &to)
 constructs a vector from two other vectors
 vector (const vector &other)
 the copy constructor
 ~vector ()
 the distructor
realx ()
 accessor for the x component (can be used as l-value too)
realy ()
 accessor for the y component (can be used as l-value too)
realz ()
 accessor for the z component (can be used as l-value too)
real x () const
 returns the x component (r-value only)
real y () const
 returns the y component (r-value only)
real z () const
 returns the z component (r-value only)
vectoroperator= (const vector &other)
 the assignment
vectoroperator+= (const vector &other)
 the sum & assign
vectoroperator-= (const vector &other)
 the subtract & assign
vectoroperator *= (const real &fact)
 the short multiply by a scalar factor & assign
vectoroperator/= (const real &fact)
 the short divide by a scalar factor & assign
realoperator[] (const int &index)
 an "access like a C++ vector"
 operator double * ()
 the conversion to a 3 double elements C++ vector
real normalize ()
 normalize the vector
vector normalized () const
 normalized copy of the vector
real length () const
 get the length of the vector
real length2 () const
 get the squared length of the vector
void EpsilonCorrect (const vector &v)
 if the vector is almost equal to the origin substitute it with v

Static Public Member Functions

static int howMany ()
 returns how many vector objects exists

Private Attributes

real vec [3]
 the actual vector

Static Private Attributes

static int counter = 0
 counts how many vector objects are present

Friends

int operator== (const vector &v1, const vector &v2)
 the equality operator
int operator!= (const vector &v1, const vector &v2)
 the inequality operator
vector operator+ (const vector &v1, const vector &v2)
 the sum
vector operator- (const vector &v1, const vector &v2)
 the difference
vector operator- (const vector &v1)
 the negation
real operator * (const vector &v1, const vector &v2)
 the vector dot product
vector operator^ (const vector &v1, const vector &v2)
 the vector cross product
vector operator * (const vector &v, const real &fact)
 the multiply a vector by a scalar factor
vector operator * (const real &fact, const vector &v)
 the multiply a scalar factor by a vector
vector operator/ (const vector &v, const real &fact)
 the divide a vector by a scalar factor
vector Bisect (vector v0, vector v1)
 returns the unit vector which halves the arc between v0 and v1
void clamp (vector &vec, const real &low, const real &high)
 clamps all the vector components between the given tresholds
ostream & operator<< (ostream &os, const vector &vect)
 the print vector to C++ stream

Constructor & Destructor Documentation

vector (  )  [inline]

default constructor

vector ( const real x,
const real y,
const real z 
) [inline]

constructs a vector from three values

vector ( vector from,
vector to 
) [inline]

constructs a vector from two other vectors

This function constructs the vector which goes from the vector from to the vector to. It is useful when a vector has to be constructed from the difference of two other vectors.

Parameters:
from the first vector
to the second vector

vector ( const vector other  )  [inline]

the copy constructor

~vector (  )  [inline]

the distructor


Member Function Documentation

real & x (  )  [inline]

accessor for the x component (can be used as l-value too)

real & y (  )  [inline]

accessor for the y component (can be used as l-value too)

real & z (  )  [inline]

accessor for the z component (can be used as l-value too)

real x (  )  const [inline]

returns the x component (r-value only)

real y (  )  const [inline]

returns the y component (r-value only)

real z (  )  const [inline]

returns the z component (r-value only)

vector & operator= ( const vector other  )  [inline]

the assignment

vector & operator+= ( const vector other  )  [inline]

the sum & assign

vector & operator-= ( const vector other  )  [inline]

the subtract & assign

vector & operator *= ( const real fact  )  [inline]

the short multiply by a scalar factor & assign

vector & operator/= ( const real fact  )  [inline]

the short divide by a scalar factor & assign

real & operator[] ( const int &  index  )  [inline]

an "access like a C++ vector"

This operator redirects the access to the internal vector. It does make a range check on the index in debug builds trough the ANSI assert function. It can be used on both sides of an assignment.

Returns:
a reference to the requested element
Parameters:
index the index which should be one of 0,1,2

operator double * (  )  [inline]

the conversion to a 3 double elements C++ vector

this conversion operator allows to use a vector in places of a classic real[3]

this conversion operator allows to use a vector in places of a classic double[3]

real normalize (  ) 

normalize the vector

This function modifies the vector upon which has been called.

Returns:
the length of the vector before normalization, this is useful to check if the normalization operation has been numerically precise.

vector normalized (  )  const

normalized copy of the vector

This function doesn't modifies the vector upon which has been called, it returns a new vector instead.

Returns:
the normalized copy of the vector

real length (  )  const [inline]

get the length of the vector

real length2 (  )  const [inline]

get the squared length of the vector

void EpsilonCorrect ( const vector v  ) 

if the vector is almost equal to the origin substitute it with v

int howMany (  )  [inline, static]

returns how many vector objects exists

The counting of the vector objects is realized trough a static counter variable.

Returns:
the number of vector objects in memory


Friends And Related Function Documentation

int operator== ( const vector v1,
const vector v2 
) [friend]

the equality operator

This function check if all elements of v1 are equal to the corresponding elements of v2.

int operator!= ( const vector v1,
const vector v2 
) [friend]

the inequality operator

This function check if some of the elements of v1 differs from the corresponding elements of v2.

vector operator+ ( const vector v1,
const vector v2 
) [friend]

the sum

vector operator- ( const vector v1,
const vector v2 
) [friend]

the difference

vector operator- ( const vector v1  )  [friend]

the negation

real operator * ( const vector v1,
const vector v2 
) [friend]

the vector dot product

vector operator^ ( const vector v1,
const vector v2 
) [friend]

the vector cross product

vector operator * ( const vector v,
const real fact 
) [friend]

the multiply a vector by a scalar factor

This function together with operator*(real,vector) implements the commutative product of a scalar by a vector

vector operator * ( const real fact,
const vector v 
) [friend]

the multiply a scalar factor by a vector

This function together with operator*(vector,real) implements the commutative product of a scalar by a vector

vector operator/ ( const vector v,
const real fact 
) [friend]

the divide a vector by a scalar factor

vector Bisect ( vector  v0,
vector  v1 
) [friend]

returns the unit vector which halves the arc between v0 and v1

void clamp ( vector vec,
const real low,
const real high 
) [friend]

clamps all the vector components between the given tresholds

limits the vector components in a range, modifying it.

Parameters:
theVec the vector to clamp
low the lower treshold
high the higher treshold

ostream& operator<< ( ostream &  os,
const vector vect 
) [friend]

the print vector to C++ stream


Member Data Documentation

int counter = 0 [static, private]

counts how many vector objects are present

real vec[3] [private]

the actual vector