eXperiment robotics framework

Vec3 Class Reference
[Vec3]

A vector with x,y,z components. More...

#include <erf/erf_vec3.hpp>>

List of all members.

Algebraic computations



Vec3operator+= (const Vec3 &a)
Vec3operator-= (const Vec3 &a)
Vec3operator*= (float k)
Vec3operator/= (float k)
Vec3 operator+ (const Vec3 &a, const Vec3 &b)
Vec3 operator- (const Vec3 &a, const Vec3 &b)
Vec3 operator- (const Vec3 &a)
Vec3 operator* (const Vec3 &a, float k)
Vec3 operator* (float k, const Vec3 &a)
Vec3 operator/ (const Vec3 &a, float k)
bool operator!= (const Vec3 &a, const Vec3 &b)
bool operator== (const Vec3 &a, const Vec3 &b)
float operator* (const Vec3 &a, const Vec3 &b)
Vec3 cross (const Vec3 &a, const Vec3 &b)
Vec3 operator^ (const Vec3 &a, const Vec3 &b)

Public Member Functions

Setting the value


 Vec3 ()
 Vec3 (float X, float Y, float Z)
 Vec3 (const XE *xe)
template<class C>
 Vec3 (const C &c)
 Vec3 (const Vec3 &v)
Vec3operator= (const Vec3 &v)
void setValue (float X, float Y, float Z)
template<class C>
Vec3operator= (const C &c)
Accessing the value


float operator[] (int i) const
float & operator[] (int i)
 operator const float * () const
Norm of the vector


float squaredNorm () const
float norm () const
float normalize ()
Vec3 unit () const
Projection


void projectOnAxis (const Vec3 &direction)
void projectOnPlane (const Vec3 &normal)

Public Attributes

union {
   struct {
      float   x
      float   y
      float   z
   } 
   float   v_ [3]
}; 

Friends

Output stream


std::ostream & operator<< (std::ostream &o, const Vec3 &)


Detailed Description

A vector with x,y,z components.

Definition at line 20 of file erf_vec3.hpp.


Constructor & Destructor Documentation

Vec3::Vec3 (  )  [inline]

Default constructor. Value is set to (0,0,0).

Definition at line 32 of file erf_vec3.hpp.

Vec3::Vec3 ( float  X,
float  Y,
float  Z 
) [inline]

Standard constructor with the x, y and z values.

Definition at line 35 of file erf_vec3.hpp.

Vec3::Vec3 ( const XE xe  )  [inline, explicit]

Universal explicit converter from any class to Vec3. You can use your own vector class everywhere a const Vec3& parameter is required, as long as it implements the operator[ ]:

    class MyVec3
    {
    // ...
    float operator[](int i) const { returns x, y or z when i=0, 1 or 2; }
    }
     
    MyVec3 v(...);
    camera()->setPosition(v);

Note that standard vector types (stl, float[3], ...) implement this operator and can hence be used in place of Vec3. See also operator const float*() .

Definition at line 53 of file erf_vec3.hpp.

template<class C>
Vec3::Vec3 ( const C &  c  )  [inline, explicit]

Definition at line 56 of file erf_vec3.hpp.

Vec3::Vec3 ( const Vec3 v  )  [inline]

Definition at line 60 of file erf_vec3.hpp.


Member Function Documentation

Vec3& Vec3::operator= ( const Vec3 v  )  [inline]

Equal operator.

Definition at line 63 of file erf_vec3.hpp.

References x, y, and z.

void Vec3::setValue ( float  X,
float  Y,
float  Z 
) [inline]

Set the current value. Better than using operator=() with a temporary Vec3(x,y,z).

Definition at line 71 of file erf_vec3.hpp.

References x, y, and z.

template<class C>
Vec3& Vec3::operator= ( const C &  c  )  [inline]

Definition at line 80 of file erf_vec3.hpp.

References x, y, and z.

float Vec3::operator[] ( int  i  )  const [inline]

Bracket operator, with a constant return value. i must range in [0..2].

Definition at line 91 of file erf_vec3.hpp.

References v_.

float& Vec3::operator[] ( int  i  )  [inline]

Bracket operator returning an l-value. i must range in [0..2].

Definition at line 96 of file erf_vec3.hpp.

References v_.

Vec3::operator const float * (  )  const [inline]

Conversion operator returning the memory address of the vector.

Very convenient to pass a Vec3 pointer as a parameter to OpenGL functions:

    Vec3 pos, normal;
    glNormal3fv(normal);
    glVertex3fv(pos);

Definition at line 108 of file erf_vec3.hpp.

References v_.

Vec3& Vec3::operator+= ( const Vec3 a  )  [inline]

Adds a to the vector.

Definition at line 160 of file erf_vec3.hpp.

References x, y, and z.

Vec3& Vec3::operator-= ( const Vec3 a  )  [inline]

Subtracts a to the vector.

Definition at line 168 of file erf_vec3.hpp.

References x, y, and z.

Vec3& Vec3::operator*= ( float  k  )  [inline]

Multiply the vector by a scalar k.

Definition at line 176 of file erf_vec3.hpp.

References x, y, and z.

Vec3& Vec3::operator/= ( float  k  )  [inline]

Divides the vector by a scalar k.

An absolute k value lower than 1E-10 will print a warning if the library was compiled with the "debug" Qt CONFIG flag. Otherwise, no test is performed for efficiency reasons.

Definition at line 187 of file erf_vec3.hpp.

References x, y, and z.

float Vec3::squaredNorm (  )  const [inline]

Returns the squared norm of the Vec3.

Definition at line 214 of file erf_vec3.hpp.

References x, y, and z.

float Vec3::norm (  )  const [inline]

Returns the norm of the vector.

Definition at line 219 of file erf_vec3.hpp.

References x, y, and z.

Referenced by normalize(), and Quaternion::setAxisAngle().

float Vec3::normalize (  )  [inline]

Normalizes the Vec3 and returns its original norm.

Normalizing a null vector will result in NaN values.

Definition at line 226 of file erf_vec3.hpp.

References norm().

Referenced by unit().

Vec3 Vec3::unit (  )  const [inline]

Returns a unitary (normalized) representation of the vector. The original Vec3 is not modified.

Definition at line 233 of file erf_vec3.hpp.

References normalize().

void Vec3::projectOnAxis ( const Vec3 direction  ) 

void Vec3::projectOnPlane ( const Vec3 normal  ) 


Friends And Related Function Documentation

Vec3 operator+ ( const Vec3 a,
const Vec3 b 
) [friend]

Returns the sum of the two vectors.

Definition at line 116 of file erf_vec3.hpp.

Vec3 operator- ( const Vec3 a,
const Vec3 b 
) [friend]

Returns the difference of the two vectors.

Definition at line 121 of file erf_vec3.hpp.

Vec3 operator- ( const Vec3 a  )  [friend]

Unary minus operator.

Definition at line 126 of file erf_vec3.hpp.

Vec3 operator* ( const Vec3 a,
float  k 
) [friend]

Returns the product of the vector with a scalar.

Definition at line 131 of file erf_vec3.hpp.

Vec3 operator* ( float  k,
const Vec3 a 
) [friend]

Returns the product of the vector with a scalar.

Definition at line 136 of file erf_vec3.hpp.

Vec3 operator/ ( const Vec3 a,
float  k 
) [friend]

Returns the division of the vector with a scalar.

Too small k values are not tested (unless the library was compiled with the "debug" Qt CONFIG flag) and may result in NaN values.

Definition at line 144 of file erf_vec3.hpp.

bool operator!= ( const Vec3 a,
const Vec3 b 
) [friend]

Returns true only when the two vector are not equal (see operator==()).

Definition at line 149 of file erf_vec3.hpp.

bool operator== ( const Vec3 a,
const Vec3 b 
) [friend]

Returns true when the squaredNorm() of the difference vector is lower then 1E-10.

Definition at line 154 of file erf_vec3.hpp.

float operator* ( const Vec3 a,
const Vec3 b 
) [friend]

Dot product of the two Vec3.

Definition at line 195 of file erf_vec3.hpp.

Vec3 cross ( const Vec3 a,
const Vec3 b 
) [friend]

Cross product of the two Vec3. Mind the order !

Definition at line 200 of file erf_vec3.hpp.

Vec3 operator^ ( const Vec3 a,
const Vec3 b 
) [friend]

Cross product of the two vectors. Same as cross().

Definition at line 207 of file erf_vec3.hpp.

std::ostream& operator<< ( std::ostream &  o,
const Vec3  
) [friend]

Output stream operator. Enables debugging code like:

    Vec3 pos(...);
    cout << "Position=" << pos << endl;


Member Data Documentation

float Vec3::x

float Vec3::y

float Vec3::z

float Vec3::v_[3]

Definition at line 27 of file erf_vec3.hpp.

Referenced by operator const float *(), and operator[]().

union { ... }


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

The miarn project - written by Joao Xavier