dcsext.vector

Vector math library.

Contents

  1. Functions
    1. Vec2:__init(obj)
    2. Vec2.new(x, y)
    3. Vec2:set(x, y)
    4. Vec2:get()
    5. Vec2:magnitude()
    6. Vec2:translate(dx, dy)
    7. Vec2:rotate(theta)
    8. Vec3:__init(obj)
    9. Vec3.new(x, y, z)
    10. Vec3:set(x, y, z)
    11. Vec3:get()
    12. Vec3:magnitude()
    13. Vec3:translate(dx, dy, dz)
    14. Vec3:rotZ(theta)
    15. Vec3:rotX(theta)
    16. Vec3:rotY(theta)
    17. Vec3:rotAxis(axis, theta)
  2. vector
    1. _t.bearing(vec1, vec2)
    2. _t.distance(vec1, vec2)
    3. _t.unitvec
    4. _t.dot(U, V)
    5. _t.angle(A, B)
    6. _t.projection(A, B)
  3. Fields
    1. Vec2.length
    2. Vec3.length
    3. Vec3.rotate

Functions

Vec2:__init(obj)

Constructor. Create Vec2 object from obj. The constructor never fails and if no coordinate elements are detected all values will be zero.

Parameters

obj
can be a 2d or 3d object of DCS or Vector class origin the constructor will select the correct fields to convert to a normal 2d object based on some DCS particulars.

Vec2.new(x, y)

Constructor. Create Vec2 object from x and y coordinates. The constructor never fails and if no coordinate elements are detected all values will be zero.

Parameters

x
coordinate x (nil defaults to 0)
y
coordinate y (nil defaults to 0)

Vec2:set(x, y)

Reset the current Vec2 to the specified x & y values.

Parameters

x
new x coordinate (nil defaults to 0)
y
new y coordinate (nil defaults to 0)

Vec2:get()

Create a raw lua table with ‘x’ and ‘y’ keys. Used for passing to DCS functions.

Vec2:magnitude()

Calculate the vector magnitude.

Vec2:translate(dx, dy)

Translate a Vec2.

Parameters

dx
offset along x (optional)
dy
offset along y (optional)

Vec2:rotate(theta)

Rotate the 2D vector. Using standard right-hand rule rotation, counter-clockwise for positive values of theta.

Parameters

theta
rotation angle in radians (counter-clockwise positive)

Vec3:__init(obj)

Constructor. Create Vec3 object from obj. The constructor never fails and if no coordinate elements are detected all values will be zero.

Parameters

obj
can be a 2d or 3d object of DCS or Vector class origin the constructor will select the correct fields to convert to a normal 3d object based on some DCS particulars.

Vec3.new(x, y, z)

Constructor. Create Vec3 object from x, y, and z values. The constructor never fails and if no coordinate elements are detected all values will be zero.

Parameters

x
coordinate x (nil defaults to 0)
y
coordinate y (nil defaults to 0)
z
coordinate z (nil defaults to 0)

Vec3:set(x, y, z)

Reset the current Vec3 to the specified x, y, & z values.

Parameters

x
new x coordinate (nil defaults to 0)
y
new y coordinate (nil defaults to 0)
z
new z coordinate (nil defaults to 0)

Vec3:get()

Create a raw lua table with ‘x’, ‘y’, and ‘z’ keys. Used for passing to DCS functions.

Vec3:magnitude()

Calculate the vector magnitude.

Vec3:translate(dx, dy, dz)

Translate a Vec3.

Parameters

dx
offset along x (optional)
dy
offset along y (optional)
dz
offset along z (optional)

Vec3:rotZ(theta)

Rotate Vec3 about the Z axis.

Parameters

theta
angle of rotation in radians (right-hand rule about Z axis)

Vec3:rotX(theta)

Rotate Vec3 about the X axis.

Parameters

theta
angle of rotation in radians (right-hand rule about X axis)

Vec3:rotY(theta)

Rotate Vec3 about the Y axis.

Parameters

theta
angle of rotation in radians (right-hand rule about Y axis)

Vec3:rotAxis(axis, theta)

Rotate Vec3 about an arbitrary axis using Rodrigues’ rotation formula. Positive values of theta rotate according to the right-hand rule about the axis.

Parameters

axis
non-zero axis of rotation, any table convertible by the Vec3 constructor; the axis is normalized internally
theta
angle of rotation in radians

Returns

  • the rotated vector

vector

_t.bearing(vec1, vec2)

Get the bearing or azimuth between two points.

Parameters

vec1
vector/point the bearing is measured from
vec2
optional will be assumed to be zero,zero

Returns

  • bearing in radians

_t.distance(vec1, vec2)

Calculate the distance between vec1 and vec2.

Parameters

vec1
first vector.
vec2
second vector.

Returns

  • distance between vec1 and vec2

_t.unitvec

Calculate the unit vector of vec.

Parameters

vec
vector to calculate the unit vector of.

_t.dot(U, V)

Dot product of vectors U and V. The vectors must be of the same order.

Parameters

U
vector
V
vector

Returns

  • scalar value

_t.angle(A, B)

Angle between 2D vectors A and B in radians

Parameters

A
first vector
B
second vector

Returns

  • angle in radians

_t.projection(A, B)

Projection of A onto B.

Parameters

A
vector to project
B
vector to project onto

Returns

  • the projected vector of A onto B

Fields

Vec2.length

Alias to get the magnitude of the vector.

Vec3.length

Alias to get the magnitude of the vector.

Vec3.rotate

Alias to rotZ so the same API exists for Vec2 & Vec3 classes.