Antiprism 0.23
Public Member Functions | Static Public Member Functions

vec3d Class Reference

Vector with 3 components. More...

#include <vec3d.h>

Collaboration diagram for vec3d:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 vec3d ()
 Constructor.
 vec3d (double x_val, double y_val, double z_val)
 Constructor.
 vec3d (double *vals)
 Constructor.
 vec3d (float *vals)
 Constructor.
vec3dto_unit ()
 Convert into a unit vector with the same direction.
vec3d 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.
vec3doperator*= (double n)
 Multiply this vector by a scalar.
vec3doperator/= (double n)
 Divide this vector by a scalar.
vec3doperator+= (vec3d v)
 Add a vector to this vector.
vec3doperator-= (vec3d 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.
const double * get_v () const
 Get a pointer to the vector component array.
vec3d component (vec3d along)
 Get the component along another vector.
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 vec3d random (rand_gen &rnd)
 Get a random vector.

Detailed Description

Vector with 3 components.


Constructor & Destructor Documentation

vec3d::vec3d ( ) [inline]

Constructor.

The vector is initialised to the unset state

vec3d::vec3d ( double  x_val,
double  y_val,
double  z_val 
) [inline]

Constructor.

Parameters:
x_valfirst component
y_valsecond component
z_valthird component
vec3d::vec3d ( double *  vals) [inline]

Constructor.

Initialise from an array

Parameters:
valspointer to an array of at least three values to use as the x, y and z components
vec3d::vec3d ( float *  vals) [inline]

Constructor.

Initialise from an array

Parameters:
valspointer to an array of at least three values to use as the x, y and z components

Member Function Documentation

vec3d vec3d::component ( vec3d  along) [inline]

Get the component along another vector.

Returns:
The component vector.
void vec3d::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.
const double* vec3d::get_v ( ) const [inline]

Get a pointer to the vector component array.

Returns:
A pointer to the underlying component array.
bool vec3d::is_set ( ) const [inline]

Check whether a vector has been set.

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

Get the magnitude of the vector.

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

Get the square of the magnitude of the vector.

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

Multiply this vector by a scalar.

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

Add a vector to this vector.

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

Subtract a vector from this vector.

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

Divide this vector by a scalar.

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

Get the vector components.

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

Get the vector components.

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

Get a random vector.

Returns:
A random vector with magnitude less then or equal to one.
bool vec3d::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.
vec3d & vec3d::to_unit ( ) [inline]

Convert into a unit vector with the same direction.

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

Get a unit vector with the same direction.

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

Unset the vector.

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

double vec3d::x ( ) const [inline]

Get the x component.

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

Get the x component.

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

Get the x component.

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

Get the y component.

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

Get the x component.

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

Get the z component.

Returns:
The value of the z component.

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