|
Functions for working with three-dimensional vectors (VectorF/Point3F). More...
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. | |
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 | 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 | VectorScale (VectorF a, float scalar) |
Scales a vector by a scalar. | |
VectorF | VectorSub (VectorF a, VectorF b) |
Subtract two vectors. |
Functions for working with three-dimensional vectors (VectorF/Point3F).
VectorF VectorAdd | ( | VectorF | a, | |
VectorF | b | |||
) |
Add two vectors.
a | The first vector. | |
b | The second vector. |
//----------------------------------------------------------------------------- // // 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 );
VectorF VectorCross | ( | VectorF | a, | |
VectorF | b | |||
) |
Calculcate the cross product of two vectors.
a | The first vector. | |
b | The second vector. |
//----------------------------------------------------------------------------- // // 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 );
float VectorDist | ( | VectorF | a, | |
VectorF | b | |||
) |
Compute the distance between two vectors.
a | The first vector. | |
b | The second vector. |
//----------------------------------------------------------------------------- // // 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 );
float VectorDot | ( | VectorF | a, | |
VectorF | b | |||
) |
Compute the dot product of two vectors.
a | The first vector. | |
b | The second vector. |
//----------------------------------------------------------------------------- // // 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 );
float VectorLen | ( | VectorF | v | ) |
Calculate the magnitude of the given vector.
v | A vector. |
//----------------------------------------------------------------------------- // // 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 );
VectorF VectorLerp | ( | VectorF | a, | |
VectorF | b, | |||
float | t | |||
) |
Linearly interpolate between two vectors by t.
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. |
//----------------------------------------------------------------------------- // // 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 );
VectorF VectorNormalize | ( | VectorF | v | ) |
Brings a vector into its unit form, i.e. such that it has the magnitute 1.
v | The vector to normalize. |
//----------------------------------------------------------------------------- // // 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 );
MatrixF VectorOrthoBasis | ( | AngAxisF | aa | ) |
Create an orthogonal basis from the given vector.
aaf | The vector to create the orthogonal basis from. |
VectorF VectorScale | ( | VectorF | a, | |
float | scalar | |||
) |
Scales a vector by a scalar.
a | The vector to scale. | |
scalar | The scale factor. |
//----------------------------------------------------------------------------- // // 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 );
VectorF VectorSub | ( | VectorF | a, | |
VectorF | b | |||
) |
Subtract two vectors.
a | The first vector. | |
b | The second vector. |
//----------------------------------------------------------------------------- // // 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 );