//////////////////////////////////////////////////////////////////////////////////////
// description: represents a 3-dimensional Vector
//
// author: runtimeTerror ([[Email Removed]] - http://www.kaiundina.de)
// last modified: 2003-07-30 20-30
//
#if !defined(_VECTOR3D_INCLUDED)
#define _VECTOR3D_INCLUDED
// Type to use for vector-components (should be double or float)
#define TYPE double
// often used parameters
#define PARAM_T TYPE x, TYPE y, TYPE z // 3 Coordinates of TYPE
#define PARAM_O Vector3D& v // 1 Vector-object as alias called v
#define PARAM_P Vector3D* v // 1 Vector-reference as pointer
// often used combinations of those parameters
#define PARAM_TT TYPE x1, TYPE y1, TYPE z1, TYPE x2, TYPE y2, TYPE z2
#define PARAM_TP TYPE x1, TYPE y1, TYPE z1, Vector3D* v2
#define PARAM_TO TYPE x1, TYPE y1, TYPE z1, Vector3D& v2
#define PARAM_PT Vector3D* v1, TYPE x2, TYPE y2, TYPE z2
#define PARAM_PP Vector3D* v1, Vector3D* v2
#define PARAM_PO Vector3D* v1, Vector3D& v2
#define PARAM_OT Vector3D& v1, TYPE x2, TYPE y2, TYPE z2
#define PARAM_OP Vector3D& v1, Vector3D* v2
#define PARAM_OO Vector3D& v1, Vector3D& v2
class Vector3D {
public:
TYPE x, y, z; // the 3 vector-components
//////////////////////////////////////////////////////////////////////////////////////
// Constructors
Vector3D();
Vector3D(TYPE xyz);
Vector3D(PARAM_T);
Vector3D(PARAM_P);
Vector3D(PARAM_O);
///////////////////////////////////////////////////
// methods for debugging purposes
///////////////////////////////////////////////////
///////////////////////////////////////////////////
// Dumps the data describing the current instance followed by a '\n'
void dump();
///////////////////////////////////////////////////
// Dumps the data describing the current instance followed by a '\n'
// the string in indent is printed out before each line
void dump(char* indent);
///////////////////////////////////////////////////
// methods using two vectors
// if the first one is omitted, 'this' is used instead
///////////////////////////////////////////////////
///////////////////////////////////////////////////
// adds two vectors
// returns result in a new instance
static Vector3D add (PARAM_TT);
static Vector3D add (PARAM_TP);
static Vector3D add (PARAM_TO);
static Vector3D add (PARAM_PT);
static Vector3D add (PARAM_PP);
static Vector3D add (PARAM_PO);
static Vector3D add (PARAM_OT);
static Vector3D add (PARAM_OP);
static Vector3D add (PARAM_OO);
Vector3D operator + (PARAM_P);
Vector3D operator + (PARAM_O);
// applied on the current instance
Vector3D* add (PARAM_T);
Vector3D* add (PARAM_P);
Vector3D* add (PARAM_O);
Vector3D* operator += (PARAM_P);
Vector3D* operator += (PARAM_O);
///////////////////////////////////////////////////
// substracts the second from the first vector
// returns result in a new instance
static Vector3D sub (PARAM_TT);
static Vector3D sub (PARAM_TP);
static Vector3D sub (PARAM_TO);
static Vector3D sub (PARAM_PT);
static Vector3D sub (PARAM_PP);
static Vector3D sub (PARAM_PO);
static Vector3D sub (PARAM_OT);
static Vector3D sub (PARAM_OP);
static Vector3D sub (PARAM_OO);
Vector3D operator - (PARAM_P);
Vector3D operator - (PARAM_O);
// applied on the current instance
Vector3D* sub (PARAM_T);
Vector3D* sub (PARAM_P);
Vector3D* sub (PARAM_O);
Vector3D* operator -= (PARAM_P);
Vector3D* operator -= (PARAM_O);
///////////////////////////////////////////////////
// substracts the first from the second vector
// applied on the current instance
Vector3D* xsub (PARAM_T);
Vector3D* xsub (PARAM_P);
Vector3D* xsub (PARAM_O);
///////////////////////////////////////////////////
// scalar-multiplication of two vectors
// returns result using two external vectors
static TYPE smul (PARAM_TT);
static TYPE smul (PARAM_TP);
static TYPE smul (PARAM_TO);
static TYPE smul (PARAM_PT);
static TYPE smul (PARAM_PP);
static TYPE smul (PARAM_PO);
static TYPE smul (PARAM_OT);
static TYPE smul (PARAM_OP);
static TYPE smul (PARAM_OO);
TYPE operator * (PARAM_P);
TYPE operator * (PARAM_O);
// applied with the current instance (no changes will be made)
TYPE smul (PARAM_T);
TYPE smul (PARAM_P);
TYPE smul (PARAM_O);
///////////////////////////////////////////////////
// crossmultiplies the first with the second vector to obtain a normal vector to both
// returns result in a new instance
static Vector3D xmul (PARAM_TT);
static Vector3D xmul (PARAM_TP);
static Vector3D xmul (PARAM_TO);
static Vector3D xmul (PARAM_PT);
static Vector3D xmul (PARAM_PP);
static Vector3D xmul (PARAM_PO);
static Vector3D xmul (PARAM_OT);
static Vector3D xmul (PARAM_OP);
static Vector3D xmul (PARAM_OO);
Vector3D operator ^ (PARAM_P);
Vector3D operator ^ (PARAM_O);
// applied on the current instance
Vector3D* xmul (PARAM_T);
Vector3D* xmul (PARAM_P);
Vector3D* xmul (PARAM_O);
Vector3D* operator ^= (PARAM_P);
Vector3D* operator ^= (PARAM_O);
///////////////////////////////////////////////////
// crossmultiplies the first with the second vector to obtain a normal vector to both
// applied on the current instance
Vector3D* xxmul (PARAM_T);
Vector3D* xxmul (PARAM_P);
Vector3D* xxmul (PARAM_O);
///////////////////////////////////////////////////
// projects the first onto the second vector
// b mustn't be (0.0, 0.0, 0.0)
// a onto b = (a*b)/(b*b)*b
// returns result in a new instance
static Vector3D projectTo (PARAM_TT);
static Vector3D projectTo (PARAM_TP);
static Vector3D projectTo (PARAM_TO);
static Vector3D projectTo (PARAM_PT);
static Vector3D projectTo (PARAM_PP);
static Vector3D projectTo (PARAM_PO);
static Vector3D projectTo (PARAM_OT);
static Vector3D projectTo (PARAM_OP);
static Vector3D projectTo (PARAM_OO);
// applied on the current instance
Vector3D* projectTo (PARAM_T);
Vector3D* projectTo (PARAM_P);
Vector3D* projectTo (PARAM_O);
///////////////////////////////////////////////////
// reflects the vector on the plane having the parameter-vector as normal
// applied on the current instance
Vector3D* reflectTo (PARAM_P);
Vector3D* reflectAbsorbedTo (PARAM_P, TYPE factor);
///////////////////////////////////////////////////
// projects the second onto the fist vector
// a mustn't be (0.0, 0.0, 0.0)
// b onto a = (b*a)/(a*a)*a
// applied on the current instance
Vector3D* projectFrom (PARAM_T);
Vector3D* projectFrom (PARAM_P);
Vector3D* projectFrom (PARAM_O);
///////////////////////////////////////////////////
// determines the sine of the smallest angle between two vectors
// none of the vectors must be (0.0, 0.0, 0.0)
// returns result using two external vectors
static TYPE sin (PARAM_TT);
static TYPE sin (PARAM_TP);
static TYPE sin (PARAM_TO);
static TYPE sin (PARAM_PT);
static TYPE sin (PARAM_PP);
static TYPE sin (PARAM_PO);
static TYPE sin (PARAM_OT);
static TYPE sin (PARAM_OP);
static TYPE sin (PARAM_OO);
// applied with the current instance (no changes will be made)
TYPE sin (PARAM_T);
TYPE sin (PARAM_P);
TYPE sin (PARAM_O);
///////////////////////////////////////////////////
// determines the cosine of the smallest angle between two vectors
// none of the vectors must be (0.0, 0.0, 0.0)
// returns result using two external vectors
static TYPE cos (PARAM_TT);
static TYPE cos (PARAM_TP);
static TYPE cos (PARAM_TO);
static TYPE cos (PARAM_PT);
static TYPE cos (PARAM_PP);
static TYPE cos (PARAM_PO);
static TYPE cos (PARAM_OT);
static TYPE cos (PARAM_OP);
static TYPE cos (PARAM_OO);
// applied with the current instance (no changes will be made)
TYPE cos (PARAM_T);
TYPE cos (PARAM_P);
TYPE cos (PARAM_O);
///////////////////////////////////////////////////
// determines the smallest angle between two vectors
// none of the vectors must be (0.0, 0.0, 0.0)
// returns result using two external vectors
static TYPE angle (PARAM_TT);
static TYPE angle (PARAM_TP);
static TYPE angle (PARAM_TO);
static TYPE angle (PARAM_PT);
static TYPE angle (PARAM_PP);
static TYPE angle (PARAM_PO);
static TYPE angle (PARAM_OT);
static TYPE angle (PARAM_OP);
static TYPE angle (PARAM_OO);
// applied with the current instance (no changes will be made)
TYPE angle (PARAM_T);
TYPE angle (PARAM_P);
TYPE angle (PARAM_O);
///////////////////////////////////////////////////
// computes the area of the parallelogram described by the vectors
// returns result using two external vectors
static TYPE affineArea (PARAM_TT);
static TYPE affineArea (PARAM_TP);
static TYPE affineArea (PARAM_TO);
static TYPE affineArea (PARAM_PT);
static TYPE affineArea (PARAM_PP);
static TYPE affineArea (PARAM_PO);
static TYPE affineArea (PARAM_OT);
static TYPE affineArea (PARAM_OP);
static TYPE affineArea (PARAM_OO);
// applied with the current instance (no changes will be made)
TYPE affineArea (PARAM_T);
TYPE affineArea (PARAM_P);
TYPE affineArea (PARAM_O);
///////////////////////////////////////////////////
// computes the area of the triangle described by the vectors
// returns result using two external vectors
static TYPE triangleArea (PARAM_TT);
static TYPE triangleArea (PARAM_TP);
static TYPE triangleArea (PARAM_TO);
static TYPE triangleArea (PARAM_PT);
static TYPE triangleArea (PARAM_PP);
static TYPE triangleArea (PARAM_PO);
static TYPE triangleArea (PARAM_OT);
static TYPE triangleArea (PARAM_OP);
static TYPE triangleArea (PARAM_OO);
// applied with the current instance (no changes will be made)
TYPE triangleArea (PARAM_T);
TYPE triangleArea (PARAM_P);
TYPE triangleArea (PARAM_O);
///////////////////////////////////////////////////
// returns true if both vectors are equal (or unequal in case of operator '!=')
// returns result in a new instance
static bool equals (PARAM_TT);
static bool equals (PARAM_TP);
static bool equals (PARAM_TO);
static bool equals (PARAM_PT);
static bool equals (PARAM_PP);
static bool equals (PARAM_PO);
static bool equals (PARAM_OT);
static bool equals (PARAM_OP);
static bool equals (PARAM_OO);
bool operator == (PARAM_P);
bool operator == (PARAM_O);
bool operator != (PARAM_P);
bool operator != (PARAM_O);
// applied on the current instance
bool equals (PARAM_T);
bool equals (PARAM_P);
bool equals (PARAM_O);
///////////////////////////////////////////////////
// methods using one vector
// if the vector is omitted, 'this' is used instead
///////////////////////////////////////////////////
///////////////////////////////////////////////////
// initializes the current instance with new values
Vector3D* set (PARAM_T);
Vector3D* set (PARAM_P);
Vector3D* set (PARAM_O);
Vector3D* operator = (PARAM_P);
Vector3D* operator = (PARAM_O);
///////////////////////////////////////////////////
// multiplies (scales) a vector with a number (s)
static Vector3D scale (PARAM_T, TYPE s);
static Vector3D scale (PARAM_P, TYPE s);
static Vector3D scale (PARAM_O, TYPE s);
Vector3D operator * (TYPE s);
Vector3D* Vector3D::operator *= (TYPE s);
Vector3D* scale (TYPE s);
///////////////////////////////////////////////////
// multiplies (scales) a vector with the reziprocal value of a number (1/s)
// s mustn't be 0
static Vector3D antiscale (PARAM_T, TYPE s);
static Vector3D antiscale (PARAM_P, TYPE s);
static Vector3D antiscale (PARAM_O, TYPE s);
Vector3D operator / (TYPE s);
Vector3D* Vector3D::operator /= (TYPE s);
Vector3D* antiscale (TYPE s);
///////////////////////////////////////////////////
// computes the length of a vector
static TYPE length (PARAM_T);
static TYPE length (PARAM_P);
static TYPE length (PARAM_O);
TYPE length ();
///////////////////////////////////////////////////
// computes the square of a vector
static TYPE sqr (PARAM_T);
static TYPE sqr (PARAM_P);
static TYPE sqr (PARAM_O);
TYPE sqr ();
///////////////////////////////////////////////////
// scales a vector to ensure, it has a length of 1.0
// vector mustn't be (0.0, 0.0, 0.0)
static Vector3D unit (PARAM_T);
static Vector3D unit (PARAM_P);
static Vector3D unit (PARAM_O);
Vector3D* unit ();
///////////////////////////////////////////////////
// changes the length of a vector to 1/l (circle inversion)
// vector mustn't be (0.0, 0.0, 0.0)
// returns result in a new instance
static Vector3D reziprocal (PARAM_T);
static Vector3D reziprocal (PARAM_P);
static Vector3D reziprocal (PARAM_O);
// applied on the current instance
Vector3D* reziprocal ();
///////////////////////////////////////////////////
// inverts the orientation of a vector
// returns result in a new instance
static Vector3D neg (PARAM_T);
static Vector3D neg (PARAM_P);
static Vector3D neg (PARAM_O);
// applied on the current instance
Vector3D* neg ();
///////////////////////////////////////////////////
// returns a copy of a vector as new instance
static Vector3D copy (PARAM_T);
static Vector3D copy (PARAM_P);
static Vector3D copy (PARAM_O);
Vector3D copy ();
///////////////////////////////////////////////////
// sets the current instance to (0.0, 0.0, 0.0)
Vector3D* clear ();
};
#endif