Vectors
Functions
VectorF
VectorAdd(VectorF a, VectorF b)
Add two vectors.
VectorF
VectorCross(VectorF a, VectorF b)
Calculcate the cross product of two vectors.
float
VectorDist(VectorF a, VectorF b)
Compute the distance between two vectors.
VectorF
VectorDiv(VectorF a, VectorF b)
Divide two vectors.
float
VectorDot(VectorF a, VectorF b)
Compute the dot product of two vectors.
float
VectorLen(VectorF v)
Calculate the magnitude of the given vector.
VectorF
VectorLerp(VectorF a, VectorF b, float t)
Linearly interpolate between two vectors by t.
VectorF
VectorMidPoint(VectorF a, VectorF b)
Gets the midpoint between the two vectors.
VectorF
VectorMul(VectorF a, VectorF b)
Multiplies two vectors.
VectorF
VectorNormalize(VectorF v)
Brings a vector into its unit form, i.e. such that it has the magnitute 1.
MatrixF
VectorOrthoBasis(AngAxisF aa)
Create an orthogonal basis from the given vector.
VectorF
VectorReflect(VectorF vec, VectorF normal)
Compute the reflection of a vector based on a normal.
VectorF
VectorScale(VectorF a, float scalar)
Scales a vector by a scalar.
VectorF
VectorSub(VectorF a, VectorF b)
Subtract two vectors.
Detailed Description
Functions
VectorAdd(VectorF a, VectorF b)
Add two vectors.
Parameters:
a | The first vector. |
b | The second vector. |
The vector a + b.
//----------------------------------------------------------------------------- // // VectorAdd( %a, %b ); // // The sum of vector a, (ax, ay, az), and vector b, (bx, by, bz) is: // // a + b = ( ax + bx, ay + by, az + bz ) // //----------------------------------------------------------------------------- %a = "1 0 0"; %b = "0 1 0"; // %r = "( 1 + 0, 0 + 1, 0 + 0 )"; // %r = "1 1 0"; %r = VectorAdd( %a, %b );
VectorCross(VectorF a, VectorF b)
Calculcate the cross product of two vectors.
Parameters:
a | The first vector. |
b | The second vector. |
The cross product x b.
//----------------------------------------------------------------------------- // // VectorCross( %a, %b ); // // The cross product of vector a, (ax, ay, az), and vector b, (bx, by, bz), is // // a x b = ( ( ay * bz ) - ( az * by ), ( az * bx ) - ( ax * bz ), ( ax * by ) - ( ay * bx ) ) // //----------------------------------------------------------------------------- %a = "1 1 0"; %b = "2 0 1"; // %r = "( ( 1 * 1 ) - ( 0 * 0 ), ( 0 * 2 ) - ( 1 * 1 ), ( 1 * 0 ) - ( 1 * 2 ) )"; // %r = "1 -1 -2"; %r = VectorCross( %a, %b );
VectorDist(VectorF a, VectorF b)
Compute the distance between two vectors.
Parameters:
a | The first vector. |
b | The second vector. |
The length( b - a ).
//----------------------------------------------------------------------------- // // VectorDist( %a, %b ); // // The distance between vector a, (ax, ay, az), and vector b, (bx, by, bz), is // // a -> b = ||( b - a )|| // = ||( bx - ax, by - ay, bz - az )|| // = mSqrt( ( bx - ax ) * ( bx - ax ) + ( by - ay ) * ( by - ay ) + ( bz - az ) * ( bz - az ) ) // //----------------------------------------------------------------------------- %a = "1 1 0"; %b = "2 0 1"; // %r = mSqrt( ( 2 - 1 ) * ( 2 - 1) + ( 0 - 1 ) * ( 0 - 1 ) + ( 1 - 0 ) * ( 1 - 0 ) ); // %r = mSqrt( 3 ); %r = VectorDist( %a, %b );
VectorDiv(VectorF a, VectorF b)
Divide two vectors.
Parameters:
a | The first vector. |
b | The second vector. |
The vector a / b.
//----------------------------------------------------------------------------- // // VectorDiv( %a, %b ); // // The division of vector a, (ax, ay, az), and vector b, (bx, by, bz) is: // // a * b = ( ax / bx, ay / by, az / bz ) // //----------------------------------------------------------------------------- %a = "1 1 1"; %b = "2 2 2"; // %r = "( 1 / 2, 1 / 2, 1 / 2 )"; // %r = "0.5 0.5 0.5"; %r = VectorDiv( %a, %b );
VectorDot(VectorF a, VectorF b)
Compute the dot product of two vectors.
Parameters:
a | The first vector. |
b | The second vector. |
The dot product a * b.
//----------------------------------------------------------------------------- // // VectorDot( %a, %b ); // // The dot product between vector a, (ax, ay, az), and vector b, (bx, by, bz), is: // // a . b = ( ax * bx + ay * by + az * bz ) // //----------------------------------------------------------------------------- %a = "1 1 0"; %b = "2 0 1"; // %r = "( 1 * 2 + 1 * 0 + 0 * 1 )"; // %r = 2; %r = VectorDot( %a, %b );
VectorLen(VectorF v)
Calculate the magnitude of the given vector.
Parameters:
v | A vector. |
The length of vector v.
//----------------------------------------------------------------------------- // // VectorLen( %a ); // // The length or magnitude of vector a, (ax, ay, az), is: // // ||a|| = Sqrt( ax * ax + ay * ay + az * az ) // //----------------------------------------------------------------------------- %a = "1 1 0"; // %r = mSqrt( 1 * 1 + 1 * 1 + 0 * 0 ); // %r = mSqrt( 2 ); // %r = 1.414; %r = VectorLen( %a );
VectorLerp(VectorF a, VectorF b, float t)
Linearly interpolate between two vectors by t.
Parameters:
a | Vector to start interpolation from. |
b | Vector to interpolate to. |
t | Interpolation factor (0-1). At zero, a is returned and at one, b is returned. In between, an interpolated vector between a and b is returned. |
An interpolated vector between a and b.
//----------------------------------------------------------------------------- // // VectorLerp( %a, %b ); // // The point between vector a, (ax, ay, az), and vector b, (bx, by, bz), which is // weighted by the interpolation factor, t, is // // r = a + t * ( b - a ) // = ( ax + t * ( bx - ax ), ay + t * ( by - ay ), az + t * ( bz - az ) ) // //----------------------------------------------------------------------------- %a = "1 1 0"; %b = "2 0 1"; %v = "0.25"; // %r = "( 1 + 0.25 * ( 2 - 1 ), 1 + 0.25 * ( 0 - 1 ), 0 + 0.25 * ( 1 - 0 ) )"; // %r = "1.25 0.75 0.25"; %r = VectorLerp( %a, %b );
VectorMidPoint(VectorF a, VectorF b)
Gets the midpoint between the two vectors.
Parameters:
a | The first vector. |
b | The second vector. |
The vector (a + b) / 2.
//----------------------------------------------------------------------------- // // VectorMidPoint( %a, %b ); // // The midpoint of vector a, (ax, ay, az), and vector b, (bx, by, bz) is: // // (a + b)/2 = ( (ax + bx) /2, ay + by) /2, (az + bz) /2 ) // //-----------------------------------------------------------------------------
VectorMul(VectorF a, VectorF b)
Multiplies two vectors.
Parameters:
a | The first vector. |
b | The second vector. |
The vector a * b.
//----------------------------------------------------------------------------- // // VectorMul( %a, %b ); // // The multiplication of vector a, (ax, ay, az), and vector b, (bx, by, bz) is: // // a * b = ( ax * bx, ay * by, az * bz ) // //----------------------------------------------------------------------------- %a = "1 0 0"; %b = "0 1 0"; // %r = "( 1 * 0, 0 * 1, 0 * 0 )"; // %r = "0 0 0"; %r = VectorMul( %a, %b );
VectorNormalize(VectorF v)
Brings a vector into its unit form, i.e. such that it has the magnitute 1.
Parameters:
v | The vector to normalize. |
The vector v scaled to length 1.
//----------------------------------------------------------------------------- // // VectorNormalize( %a ); // // The normalized vector a, (ax, ay, az), is: // // a^ = a / ||a|| // = ( ax / ||a||, ay / ||a||, az / ||a|| ) // //----------------------------------------------------------------------------- %a = "1 1 0"; %l = 1.414; // %r = "( 1 / 1.141, 1 / 1.141, 0 / 1.141 )"; // %r = "0.707 0.707 0"; %r = VectorNormalize( %a );
VectorOrthoBasis(AngAxisF aa)
Create an orthogonal basis from the given vector.
Parameters:
aaf | The vector to create the orthogonal basis from. |
A matrix representing the orthogonal basis.
VectorReflect(VectorF vec, VectorF normal)
Compute the reflection of a vector based on a normal.
Parameters:
a | The vector. |
b | The normal. |
The reflected vector.
VectorScale(VectorF a, float scalar)
Scales a vector by a scalar.
Parameters:
a | The vector to scale. |
scalar | The scale factor. |
The vector a * scalar.
//----------------------------------------------------------------------------- // // VectorScale( %a, %v ); // // Scaling vector a, (ax, ay, az), but the scalar, v, is: // // a * v = ( ax * v, ay * v, az * v ) // //----------------------------------------------------------------------------- %a = "1 1 0"; %v = "2"; // %r = "( 1 * 2, 1 * 2, 0 * 2 )"; // %r = "2 2 0"; %r = VectorScale( %a, %v );
VectorSub(VectorF a, VectorF b)
Subtract two vectors.
Parameters:
a | The first vector. |
b | The second vector. |
The vector a - b.
//----------------------------------------------------------------------------- // // VectorSub( %a, %b ); // // The difference of vector a, (ax, ay, az), and vector b, (bx, by, bz) is: // // a - b = ( ax - bx, ay - by, az - bz ) // //----------------------------------------------------------------------------- %a = "1 0 0"; %b = "0 1 0"; // %r = "( 1 - 0, 0 - 1, 0 - 0 )"; // %r = "1 -1 0"; %r = VectorSub( %a, %b );