Antiprism 0.23
Public Member Functions | Static Public Member Functions

vec4d Class Reference

Vector with 4 components. More...

#include <vec4d.h>

Collaboration diagram for vec4d:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 vec4d ()
 Constructor.
 vec4d (double x, double y, double z, double w)
 Constructor.
vec4dto_unit ()
 Convert into a unit vector with the same direction.
vec4d unit () const
 Get a unit vector with the same direction.
double mag () const
 Get the magnitude of the vector.
double mag2 () const
 Get the square of the magnitude of the vector.
vec4doperator*= (double n)
 Multiply this vector by a scalar.
vec4doperator/= (double n)
 Divide this vector by a scalar.
vec4doperator+= (vec4d v)
 Add a vector to this vector.
vec4doperator-= (vec4d v)
 Subtract a vector from this vector.
double operator[] (int idx) const
 Get the vector components.
double & operator[] (int idx)
 Get the vector components.
double x () const
 Get the x component.
double & x ()
 Get the x component.
double y () const
 Get the y component.
double & y ()
 Get the x component.
double z () const
 Get the z component.
double & z ()
 Get the x component.
double w () const
 Get the w component.
double & w ()
 Get the w component.
void unset ()
 Unset the vector.
bool is_set () const
 Check whether a vector has been set.
bool read (const char *str, char *errmsg=0)
 Read a vector from a string.
void dump (const char *var="", FILE *file=stderr) const
 Debugging print of a vector variable.

Static Public Member Functions

static vec4d random (rand_gen &rnd)
 Get a random vector.

Detailed Description

Vector with 4 components.


Constructor & Destructor Documentation

vec4d::vec4d ( ) [inline]

Constructor.

The vector is initialised to the unset state

vec4d::vec4d ( double  x,
double  y,
double  z,
double  w 
) [inline]

Constructor.

Parameters:
xfirst component
ysecond component
zthird component
wfourth component

Member Function Documentation

void vec4d::dump ( const char *  var = "",
FILE *  file = stderr 
) const

Debugging print of a vector variable.

Parameters:
vara string to identify the vector variable.
filefile stream to print the variable.
bool vec4d::is_set ( ) const [inline]

Check whether a vector has been set.

Returns:
true if set, otherwise false
double vec4d::mag ( ) const [inline]

Get the magnitude of the vector.

Returns:
The magnitude.
double vec4d::mag2 ( ) const [inline]

Get the square of the magnitude of the vector.

Returns:
The square of the magnitude.
vec4d & vec4d::operator*= ( double  n) [inline]

Multiply this vector by a scalar.

Returns:
A reference to this vector.
vec4d & vec4d::operator+= ( vec4d  v) [inline]

Add a vector to this vector.

Returns:
A reference to this vector.
vec4d & vec4d::operator-= ( vec4d  v) [inline]

Subtract a vector from this vector.

Returns:
A reference to this vector.
vec4d & vec4d::operator/= ( double  n) [inline]

Divide this vector by a scalar.

Returns:
A reference to this vector.
double vec4d::operator[] ( int  idx) const [inline]

Get the vector components.

Parameters:
idxthe component index.
Returns:
The value of the component.
double& vec4d::operator[] ( int  idx) [inline]

Get the vector components.

Parameters:
idxthe component index.
Returns:
A reference to the component.
vec4d vec4d::random ( rand_gen &  rnd) [inline, static]

Get a random vector.

Returns:
A random vector with magnitude less then or equal to one.
bool vec4d::read ( const char *  str,
char *  errmsg = 0 
)

Read a vector from a string.

Parameters:
stra string containing three decimals separated by commas or spaces.
errmsgan array at least MSG_SZ chars long to return any error message.
Returns:
true if a valid vector was read, otherwise false and the error is detailed in errmsg.
vec4d & vec4d::to_unit ( ) [inline]

Convert into a unit vector with the same direction.

Returns:
A reference to the vector.
vec4d vec4d::unit ( ) const [inline]

Get a unit vector with the same direction.

Returns:
The unit vector.
void vec4d::unset ( )

Unset the vector.

Put the vector into the initial unset state. The vector will return false if tested

double& vec4d::w ( ) [inline]

Get the w component.

Returns:
The value of the x component.
double vec4d::w ( ) const [inline]

Get the w component.

Returns:
The value of the z component.
double vec4d::x ( ) const [inline]

Get the x component.

Returns:
The value of the x component.
double& vec4d::x ( ) [inline]

Get the x component.

Returns:
The value of the x component.
double& vec4d::y ( ) [inline]

Get the x component.

Returns:
The value of the x component.
double vec4d::y ( ) const [inline]

Get the y component.

Returns:
The value of the y component.
double vec4d::z ( ) const [inline]

Get the z component.

Returns:
The value of the z component.
double& vec4d::z ( ) [inline]

Get the x component.

Returns:
The value of the x component.

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