Module vector

Vector/coordinate utilities.

Functions

vector.canonicalDeg(deg[, half]) Convert an angle (deg) to its canonical value.
vector.radFromDeg(deg) Convert an angle in degrees to radians.
vector.radFromHeading(heading) Convert a heading to radians clockwise from East.
vector.degFromRad(rad) Convert an angle in radians to degrees.
vector.degFromHeading(heading) Convert a heading to degrees clockwise from East.
vector.headingFromDeg(deg) Convert an angle clockwise from East in degrees to a heading.
vector.headingFromRad(rad) Convert an angle clockwise from East in radians to a heading.
vector.xyFromRadialRad(rtheta) Convert r-theta coordinates (rad) to the equivalent x-y coordinates.
vector.xyFromRadialDeg(rtheta) Convert r-theta coordinates (deg) to the equivalent x-y coordinates.
vector.xyFromRadialHeading(rtheta) Convert r-theta coordinates (heading) to the equivalent x-y coordinates.
vector.radialRadFromXY(xy) Convert x-y coordinates to the equivalent r-theta coordinates (rad).
vector.radialDegFromXY(xy) Convert x-y coordinates to the equivalent r-theta coordinates (deg).
vector.radialHeadingFromXY(xy) Convert x-y coordinates to the equivalent r-theta coordinates (heading).
vector.xyRotateRad(xy, rad) Rotate a vector clockwise by an angle.
vector.xyRotateDeg(xy, deg) Rotate a vector clockwise by an angle.
vector.xyAdd(v1, v2) Add two vectors.
vector.xyMul(v, s) Multiply a vector by a scalar.
vector.xyNormalise(v) Normalise a vector.
vector.xyLength(v) Calculate the length of a vector.
vector.xySub(v1, v2) Subtract a vector from another, or find the vector between two points.
vector.distance(p1, p2) Get the distance between two points.
vector.xyFloor(xy) Floor the elements of a vector.

Argument Types

rtheta A point in a polar coordinate space.
xy A point in a Cartesian coordinate space.


Functions

vector.canonicalDeg(deg[, half])
Convert an angle (deg) to its canonical value. By default, this places the angle in the range [0, 360). If half is true, the angle is instead placed in (-180, 180].

Parameters:

  • deg number The angle to canonicalise.
  • half boolean Whether to canonicalise to half-turn from centre. (optional)
vector.radFromDeg(deg)
Convert an angle in degrees to radians.

Parameters:

  • deg number The angle (deg) to convert.

Returns:

    number The converted angle (rad).
vector.radFromHeading(heading)
Convert a heading to radians clockwise from East.

Parameters:

  • heading number The heading to convert.

Returns:

    number The converted angle (rad).
vector.degFromRad(rad)
Convert an angle in radians to degrees.

Parameters:

  • rad number The angle (rad) to convert.

Returns:

    number The converted angle (deg).
vector.degFromHeading(heading)
Convert a heading to degrees clockwise from East.

Parameters:

  • heading number The heading to convert.

Returns:

    number The converted angle (deg).
vector.headingFromDeg(deg)
Convert an angle clockwise from East in degrees to a heading.

Parameters:

  • deg number The angle (deg) to convert.

Returns:

    number The converted heading.
vector.headingFromRad(rad)
Convert an angle clockwise from East in radians to a heading.

Parameters:

  • rad number The angle (rad) to convert.

Returns:

    number The converted heading.
vector.xyFromRadialRad(rtheta)
Convert r-theta coordinates (rad) to the equivalent x-y coordinates.

Parameters:

  • rtheta rtheta The coordinate (rad) to convert.

Returns:

  1. number The x coordinate of the result.
  2. number The y coordinate of the result.
vector.xyFromRadialDeg(rtheta)
Convert r-theta coordinates (deg) to the equivalent x-y coordinates.

Parameters:

  • rtheta rtheta The coordinate (deg) to convert.

Returns:

  1. number The x coordinate of the result.
  2. number The y coordinate of the result.
vector.xyFromRadialHeading(rtheta)
Convert r-theta coordinates (heading) to the equivalent x-y coordinates.

Parameters:

  • rtheta rtheta The coordinate (heading) to convert.

Returns:

  1. number The x coordinate of the result.
  2. number The y coordinate of the result.
vector.radialRadFromXY(xy)
Convert x-y coordinates to the equivalent r-theta coordinates (rad).

Parameters:

  • xy xy The coordinate to convert.

Returns:

  1. number The r coordinate of the result.
  2. number The theta coordinate (rad) of the result.
vector.radialDegFromXY(xy)
Convert x-y coordinates to the equivalent r-theta coordinates (deg).

Parameters:

  • xy xy The coordinate to convert.

Returns:

  1. number The r coordinate of the result.
  2. number The theta coordinate (deg) of the result.
vector.radialHeadingFromXY(xy)
Convert x-y coordinates to the equivalent r-theta coordinates (heading).

Parameters:

  • xy xy The coordinate to convert.

Returns:

  1. number The r coordinate of the result.
  2. number The theta coordinate (heading) of the result.
vector.xyRotateRad(xy, rad)
Rotate a vector clockwise by an angle.

Parameters:

  • xy xy The vector to rotate.
  • rad number The angle (rad) to rotate by.

Returns:

  1. number The x coordinate of the result.
  2. number The y coordinate of the result.
vector.xyRotateDeg(xy, deg)
Rotate a vector clockwise by an angle.

Parameters:

  • xy xy The vector to rotate.
  • deg number The angle (deg) to rotate by.

Returns:

  1. number The x coordinate of the result.
  2. number The y coordinate of the result.
vector.xyAdd(v1, v2)
Add two vectors.

Parameters:

  • v1 xy The first vector.
  • v2 xy The second vector.

Returns:

  1. number The x coordinate of the result.
  2. number The y coordinate of the result.
vector.xyMul(v, s)
Multiply a vector by a scalar.

Parameters:

  • v xy The vector.
  • s number The number to multiply by.

Returns:

  1. number The x coordinate of the result.
  2. number The y coordinate of the result.
vector.xyNormalise(v)
Normalise a vector.

Parameters:

  • v xy The vector.

Returns:

  1. number The x coordinate of the result.
  2. number The y coordinate of the result.
vector.xyLength(v)
Calculate the length of a vector.

Parameters:

  • v xy The vector.

Returns:

    number The length of the vector.
vector.xySub(v1, v2)
Subtract a vector from another, or find the vector between two points.

Parameters:

  • v1 xy The vector to subtract from, or the target point.
  • v2 xy The vector to subtract, or the start point.

Returns:

  1. number The x coordinate of the result.
  2. number The y coordinate of the result.
vector.distance(p1, p2)
Get the distance between two points.

Parameters:

  • p1 xy The first point.
  • p2 xy The second point.

Returns:

    number The distance between the points.
vector.xyFloor(xy)
Floor the elements of a vector.

Parameters:

  • xy xy The vector to floor.

Returns:

  1. integer The x coordinate of the result.
  2. integer The y coordinate of the result.

Argument Types

rtheta

A point in a polar coordinate space. Valid argument forms:

  • two numbers r, theta
  • a table of two numbers {r, theta}
xy

A point in a Cartesian coordinate space. Valid argument forms:

  • two numbers x, y
  • a table of two numbers {x, y}
  • an entity ent
generated by LDoc 1.5.0