Antiprism 0.23
|
Vector with 3 components. More...
#include <vec3d.h>
Public Member Functions | |
vec3d () | |
Constructor. | |
vec3d (double x_val, double y_val, double z_val) | |
Constructor. | |
vec3d (double *vals) | |
Constructor. | |
vec3d (float *vals) | |
Constructor. | |
vec3d & | to_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. | |
vec3d & | operator*= (double n) |
Multiply this vector by a scalar. | |
vec3d & | operator/= (double n) |
Divide this vector by a scalar. | |
vec3d & | operator+= (vec3d v) |
Add a vector to this vector. | |
vec3d & | operator-= (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. |
Vector with 3 components.
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.
x_val | first component |
y_val | second component |
z_val | third component |
vec3d::vec3d | ( | double * | vals | ) | [inline] |
Constructor.
Initialise from an array
vals | pointer 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
vals | pointer to an array of at least three values to use as the x, y and z components |
Get the component along another vector.
void vec3d::dump | ( | const char * | var = "" , |
FILE * | file = stderr |
||
) | const |
Debugging print of a vector variable.
var | a string to identify the vector variable. |
file | file stream to print the variable. |
const double* vec3d::get_v | ( | ) | const [inline] |
Get a pointer to the vector component array.
bool vec3d::is_set | ( | ) | const [inline] |
Check whether a vector has been set.
true
if set, otherwise false
double vec3d::mag | ( | ) | const [inline] |
Get the magnitude of the vector.
double vec3d::mag2 | ( | ) | const [inline] |
Get the square of the magnitude of the vector.
vec3d & vec3d::operator*= | ( | double | n | ) | [inline] |
Multiply this vector by a scalar.
Add a vector to this vector.
Subtract a vector from this vector.
vec3d & vec3d::operator/= | ( | double | n | ) | [inline] |
Divide this vector by a scalar.
double vec3d::operator[] | ( | int | idx | ) | const [inline] |
Get the vector components.
idx | the component index. |
double& vec3d::operator[] | ( | int | idx | ) | [inline] |
Get the vector components.
idx | the component index. |
vec3d vec3d::random | ( | rand_gen & | rnd | ) | [inline, static] |
Get a random vector.
bool vec3d::read | ( | const char * | str, |
char * | errmsg = 0 |
||
) |
Read a vector from a string.
str | a string containing three decimals separated by commas or spaces. |
errmsg | an array at least MSG_SZ chars long to return any error message. |
vec3d & vec3d::to_unit | ( | ) | [inline] |
Convert into a unit vector with the same direction.
vec3d vec3d::unit | ( | ) | const [inline] |
Get a unit vector with the same direction.
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.
double& vec3d::x | ( | ) | [inline] |
Get the x component.
double& vec3d::y | ( | ) | [inline] |
Get the x component.
double vec3d::y | ( | ) | const [inline] |
Get the y component.
double& vec3d::z | ( | ) | [inline] |
Get the x component.
double vec3d::z | ( | ) | const [inline] |
Get the z component.