TorqueScript Reference

- Main Page
- Related Pages
- Modules
- Classes

Functions
Vector Math
Function Categories

## Functions
String | VectorAdd (vecA, vecB)
String | VectorCross (vecA, vecB)
Float | VectorDist (vecA, vecB)
Float | VectorDot (vecA, vecB)
Float | VectorLen (vec)
String | VectorNormalize (vec)
String | VectorOrthoBasis (vec)
String | VectorScale (vec, scale)
String | VectorSub (vecA, vecB)

## Detailed Description

## Function Documentation

String VectorAdd | ( | vecA | ,
|  | vecB |
| ) |  |

Use the VectorAdd function to add two vectors of up to three elements each to each other

Parameters

  vecA | A vector of up to three elements.
  vecB | A vector of up to three elements.

Returns
  Returns the result of vecA + vecB.

See also
  vectorSub

String VectorCross | ( | vecA | ,
|  | vecB |
| ) |  |

Use the VectorCross function to calculate the cross product of two vectors of up to three elements each. Remember, the resultant vector will always be an right angles (orthogonal) to both input vectors.

Parameters

  vecA | A vector of up to three elements.
  vecB | A vector of up to three elements.

Returns
  Returns the result of vecA x vecB.

See also
  VectorDot

Float VectorDist | ( | vecA | ,
|  | vecB |
| ) |  |

Use the VectorDist function to calculate distance between two vectors of up to three elements each.

Parameters

  vecA | A vector of up to three elements.
  vecB | A vector of up to three elements.

Returns
  Returns the result of \ |Xa - Xb| |Ya - Yb| |Za - Zb| .

See also
  VectorLen

Float VectorDot | ( | vecA | ,
|  | vecB |
| ) |  |

Use the VectorCross function to calculate the dot product of two unit vectors of up to three elements each. Warning! Be sure to always normalize both vecA and vecB before attempting to find the dot product. Calculating a dot product using un-normalized vectors (non- unit vectors) will result in meaningless results. If the return value is < 0, the inner-angle between the vectors is > 90 degrees. If the return value is == 0, the inner-angle between the vectors is == 90 degrees. If the return value is > 0, the inner-angle between the vectors is < 90 degrees.

Parameters

  vecA | A unit-vector of up to three elements.
  vecB | A unit-vector of up to three elements.

Returns
  Returns a scalar value equal to the result of vecA . vecB. This value which will always be a single floating-point value in the range [ -1 , +1 ].

See also
  VectorCross

Float VectorLen | ( | vec |  | ) |

Use the VectorLen function to calculate the length of vector vec.

Parameters

  vec | A vector of up to three elements.

Returns
  Returns a scalar representing the length of the vector vec.

See also
  VectorDist

String VectorNormalize | ( | vec |  | ) |

Use the VectorNormalize function to calculated the unit vector equivalent of the vector vec.

Parameters

  vec | A vector of up to three elements.

Returns
  Returns the unit vector equivalent of the vector vec.

See also
  VectorScale

String VectorOrthoBasis | ( | vec |  | ) |

Use the VectorOrthoBasis function to calculate a 3x3 Row-Major formated matrix representing the orthogonal basis for the vector vec.

Parameters

  vec | A four element vector of the form AxisY AxisZ theta\, where theta is the angle of rotation about the vector formed by the prior three values.

Returns
  Returns a 3x3 Row-Major formated matrix

String VectorScale | ( | vec | ,
|  | scale |
| ) |  |

Use the VectorScale function to scale the vector vec by the scalar scale.

Parameters

  vec | A vector of up to three elements.
  scale | A numeric value (integer or floating-point) representing the scaling factor.

Returns
  Returns a scaled version of the vector vec, equivalent to: ( scale * X ) ( scale * Y ) ( scale * Z ).

See also
  VectorNormalize

String VectorSub | ( | vecA | ,
|  | vecB |
| ) |  |

Use the VectorSub function to subtract vecB from vecA.

Parameters

  vecA | Left side vector in subtraction equation.
  vecB | Right side vector in subtraction equation.

Returns
  Returns a new vector equivalent to: - vecB.

See also
  vectorAdd