Class Common.Vector
3D Vector class.
Fields
Common.Vector.x | Vector x variable. |
Common.Vector.y | Vector y variable. |
Common.Vector.z | Vector z variable. |
Methods
Common.Vector:Create (X[, Y[, Z]]) | Constructs a 3D vector. |
Common.Vector:FromString (stringVector) | Constructs a 3D vector from a string. |
Common.Vector:Clone () | Returns a clone of this vector. |
Common.Vector:Length () | Gets the length of this vector. |
Common.Vector:Normalize () | Returns the normalized form of this vector. |
Common.Vector:Make2D () | Returns the 2D form of this vector. |
Common.Vector:Length2D () | Gets the length of this vector in 2D. |
Common.Vector:ToString () | Returns a string representation of this vector. |
Common.Vector:DotProduct (v) | Returns a dot product from 2 vectors. |
Common.Vector:CrossProduct (v) | Returns a cross product from 2 vectors. |
Metamethods
Common.Vector.__index | Base class. |
Common.Vector.__tostring | Returns a string representation of this vector. |
Common.Vector:__unm () | Returns a negated form of this vector. |
Common.Vector:__eq (v) | Compares this vector. |
Common.Vector:__add (v) | Returns a vector from addition of 2 vectors. |
Common.Vector:__sub (v) | Returns a vector from subtraction of 2 vectors. |
Common.Vector:__mul (fl) | Multiplies this vector with a number value. |
Common.Vector:__div (fl) | Divides this vector with a number value. |
Fields
- Common.Vector.x
-
Vector x variable.
- x number (default 0)
- Common.Vector.y
-
Vector y variable.
- y number (default 0)
- Common.Vector.z
-
Vector z variable.
- z number (default 0)
Methods
- Common.Vector:Create (X[, Y[, Z]])
-
Constructs a 3D vector.
Parameters:
- X number or table The value of X. | The vector-compatible table.
- Y
number
The value of Y (Ignored if
X
is table). (optional) - Z
number
The value of Z (Ignored if
X
is table). (optional)
Returns:
-
Common.Vector
The new vector.
Usage:
-- You can do this. vec = Common.Vector:Create( 1 , 2 , 3 ) -- or do this. vec = Common.Vector:Create( { x = 1 , y = 2 , z = 3 } ) -- or do this. vec = Common.Vector:Create( "1 2 3" )
- Common.Vector:FromString (stringVector)
-
Constructs a 3D vector from a string.
Format should be: x y z
Parameters:
- stringVector string The string vector.
Returns:
-
Common.Vector
The new vector.
- Common.Vector:Clone ()
-
Returns a clone of this vector.
Returns:
-
Common.Vector
The new vector.
- Common.Vector:Length ()
-
Gets the length of this vector.
Returns:
-
number
The length.
- Common.Vector:Normalize ()
-
Returns the normalized form of this vector.
Returns:
-
Common.Vector
The normalized vector.
- Common.Vector:Make2D ()
-
Returns the 2D form of this vector.
Returns:
-
Common.Vector2D
The new 2D vector.
- Common.Vector:Length2D ()
-
Gets the length of this vector in 2D.
Returns:
-
number
The length.
- Common.Vector:ToString ()
-
Returns a string representation of this vector.
Returns:
-
string
The string of integers.
- Common.Vector:DotProduct (v)
-
Returns a dot product from 2 vectors.
Parameters:
- v Common.Vector The other vector.
Returns:
-
Common.Vector
The dot product.
- Common.Vector:CrossProduct (v)
-
Returns a cross product from 2 vectors.
Parameters:
- v Common.Vector The other vector.
Returns:
-
number
The cross product.
Metamethods
- Common.Vector.__index
-
Base class.
- __index Common.Vector
- Common.Vector.__tostring
-
Returns a string representation of this vector.
- __tostring Common.Vector.ToString
- Common.Vector:__unm ()
-
Returns a negated form of this vector.
Returns:
-
Common.Vector
The new vector.
Usage:
local vec = Common.Vector:Create( 1 , 2 , 3 ); vec = -vec; print( vec:ToString() ); -- prints "-1 -2 -3".
- Common.Vector:__eq (v)
-
Compares this vector.
Parameters:
- v Common.Vector The other vector.
Returns:
-
bool
Returns true if equals.
Usage:
local vec = Common.Vector:Create(); print( vec == Common.vecZero ); -- prints "true".
- Common.Vector:__add (v)
-
Returns a vector from addition of 2 vectors.
Parameters:
- v Common.Vector The other vector.
Returns:
-
Common.Vector
The new vector.
Usage:
local vec = Common.Vector:Create( 2 , 3 , 4 ); vec = vec + {x = 2 , y = 1 , z = 0}; print( vec:ToString() ); -- prints "4 4 4".
- Common.Vector:__sub (v)
-
Returns a vector from subtraction of 2 vectors.
Parameters:
- v Common.Vector The other vector.
Returns:
-
Common.Vector
The new vector.
Usage:
local vec = Common.Vector:Create( 2 , 3 , 4 ); vec = vec - {x = 2 , y = 1 , z = 3}; print( vec:ToString() ); -- prints "0 2 1".
- Common.Vector:__mul (fl)
-
Multiplies this vector with a number value.
Parameters:
- fl number The modifier.
Returns:
-
Common.Vector
The new vector.
Usage:
local vec = Common.Vector:Create( 2 , 3 , 4 ); vec = vec * 2; print( vec:ToString() ); -- prints "4 6 8".
- Common.Vector:__div (fl)
-
Divides this vector with a number value.
Parameters:
- fl number The modifier.
Returns:
-
Common.Vector
The new vector.
Usage:
local vec = Common.Vector:Create( 4 , 6 , 8 ); vec = vec / 2; print( vec:ToString() ); -- prints "2 3 4".