Main   Class List   Namespace List   Wiki

Vector Math
[Math]

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.

Detailed Description

Functions for working with three-dimensional vectors (VectorF/Point3F).


Function Documentation

VectorF VectorAdd ( VectorF  a,
VectorF  b 
)

Add two vectors.

Parameters:
a The first vector.
b The second vector.
Returns:
The vector a + b.
Example:
//-----------------------------------------------------------------------------
//
// 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.

Parameters:
a The first vector.
b The second vector.
Returns:
The cross product x b.
Example:
//-----------------------------------------------------------------------------
//
// 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.

Parameters:
a The first vector.
b The second vector.
Returns:
The length( b - a ).
Example:
//-----------------------------------------------------------------------------
//
// 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.

Parameters:
a The first vector.
b The second vector.
Returns:
The dot product a * b.
Example:
//-----------------------------------------------------------------------------
//
// 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.

Parameters:
v A vector.
Returns:
The length of vector v.
Example:
//-----------------------------------------------------------------------------
//
// 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.

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.
Returns:
An interpolated vector between a and b.
Example:
//-----------------------------------------------------------------------------
//
// 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.

Parameters:
v The vector to normalize.
Returns:
The vector v scaled to length 1.
Example:
//-----------------------------------------------------------------------------
//
// 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.

Parameters:
aaf The vector to create the orthogonal basis from.
Returns:
A matrix representing the orthogonal basis.
VectorF VectorScale ( VectorF  a,
float  scalar 
)

Scales a vector by a scalar.

Parameters:
a The vector to scale.
scalar The scale factor.
Returns:
The vector a * scalar.
Example:
//-----------------------------------------------------------------------------
//
// 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.

Parameters:
a The first vector.
b The second vector.
Returns:
The vector a - b.
Example:
//-----------------------------------------------------------------------------
//
// 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 );


Copyright © GarageGames, LLC. All Rights Reserved.