Modding:Lua/Tables/Vector2
From Starbounder - Starbound Wiki
< Modding:Lua | Tables
Description
Vector2 contains functions related to vector manipulation. A vector is a table with two values set, [1] being the x coordinate and [2] being the y coordinate.
Functions
vec2.add
Adds the given scalar_or_vector to the given vector and returns the result.
Parameters:
- vector: (table<Vector2>) The vector to modify.
- scalar_or_vector: (mixed) A Vector2 to add or a number to add.
Returns: table<Vector2>
The result of the addition.
Usage:
table<Vector2> vec2.add
(table<Vector2> vector, mixed scalar_or_vector)
See also: No related links.
vec2.angle
Calculates the angle of the given vector and returns it.
Parameters:
- vector: (table<Vector2>) The vector to calculate the angle of.
Returns: number
Returns the angle of this vector.
Usage:
number vec2.angle
(table<Vector2> vector)
See also: No related links.
vec2.div
Divides the given vector by the given scalar, returning the resulting Vector2.
Parameters:
- vector: (table<Vector2>) The vector to divide.
- scalar: (number) The value to divide the vector by.
Returns: table<Vector2>
A vector containing the result.
Usage:
table<Vector2> vec2.div
(table<Vector2> vector, number scalar)
See also: No related links.
vec2.dup
Creates an exact copy of the given vector and returns it.
Parameters:
- vector: (table<Vector2>) The vector to create a duplicate of.
Returns: table<Vector2>
An exact copy of the given vector.
Usage:
table<Vector2> vec2.dup
(table<Vector2> vector)
See also: No related links.
vec2.eq
Checks if the two vectors are equal and returns the result.
Parameters:
- vector1: (table<Vector2>) The first vector to check for equality.
- vector2: (table<Vector2>) The second vector to check for equality.
Returns: boolean
true if vector1 equals vector2, otherwise false.
Usage:
boolean vec2.eq
(table<Vector2> vector1, table<Vector2> vector2)
See also: No related links.
vec2.intersect
If line a and line b intersect at any point, returns this point as a vector, otherwise returns nil.
Parameters:
- a0: (table<Vector2>) Line A starting point.
- a1: (table<Vector2>) Line A ending point.
- b0: (table<Vector2>) Line B starting point.
- b1: (table<Vector2>) Line B ending point.
Returns: table<Vector2>
A vector containing the position where the lines intersected or nil.
Usage:
table<Vector2> vec2.intersect
(table<Vector2> a0, table<Vector2> a1, table<Vector2> b0, table<Vector2> b1)
See also: No related links.
vec2.mul
Multiplies the given vector with the given scalar, returning the resulting Vector2.
Parameters:
- vector: (table<Vector2>) The vector to multiply.
- scalar: (number) The value to multiply the vector with.
Returns: table<Vector2>
A vector containing the result.
Usage:
table<Vector2> vec2.mul
(table<Vector2> vector, number scalar)
See also: No related links.
vec2.norm
Normalizes the vector.
Parameters:
- vector: (table<Vector2>) The vector to normalize.
Returns: table<Vector2>
The normalized vector.
Usage:
table<Vector2> vec2.norm
(table<Vector2> vector)
See also: No related links.
vec2.rotate
Rotates the given vector by the given angle, returning the resulting Vector2.
Parameters:
- vector: (table<Vector2>) The vector to rotate.
- angle: (number) The angle to rotate by.
Returns: table<Vector2>
A vector containing the result.
Usage:
table<Vector2> vec2.rotate
(table<Vector2> vector, number angle)
See also: No related links.
vec2.sub
Subtracts the given scalar_or_vector from the given vector and returns the result.
Parameters:
- vector: (table<Vector2>) The vector to modify.
- scalar_or_vector: (mixed) A Vector2 or a number to subtract.
Returns: table<Vector2>
The result of the subtraction.
Usage:
table<Vector2> vec2.sub
(table<Vector2> vector, mixed scalar_or_vector)
See also: No related links.
Portal - Basics - JSON - Lua - Assets - Guides
Tables - Hooks - Tips & Tricks - Libraries - All Pages