More actions
m →# (operator): that period looks weird Tag: 2017 source edit |
m PenguinEncounter moved page Vector/Operators to Template:Main:Vector/Operators: trying to get this out of the search results |
||
(One intermediate revision by the same user not shown) | |||
Line 174: | Line 174: | ||
---- | ---- | ||
Returns the number of components in this vector {{#if:{{{Size|}}}|({{{Size}}})|.}} | Returns the number of components in this vector{{#if:{{{Size|}}}| ({{{Size}}})|.}} | ||
{| class="wikitable" | {| class="wikitable" |
Latest revision as of 23:40, 29 October 2024
Lua operators, such as +
, -
, and *
, apply to vectors and have different results.
+ (operator)
With two vectors
Adds the values from this vector and another vector of the same size. The result is a new vector of the same size which holds the sum.
Left | Right | Result |
---|---|---|
Vector | Vector | new Vector |
local a = vec(1, 2, 3)
local b = vec(4, 4, 6)
print(a + b, a, b) -- {5, 6, 9} {1, 2, 3} {4, 4, 6}
With a vector and number
The result is a new vector of the same size which holds the result of adding the number to all components of this vector.
Left | Right | Result |
---|---|---|
Vector | number | new Vector |
number | Vector | new Vector |
- (operator)
As a unary operator
Returns a new vector of the same size, but all the components negated. Effectively the same as * -1
.
Operand | Result |
---|---|
Vector | new Vector |
With two vectors
Performs vector subtraction with another vector, and creates a new vector from the result.
Subtracts the right vector from the left vector. The result is a new vector of the same size which holds the difference.
Left | Right | Result |
---|---|---|
Vector | Vector | new Vector |
local a = vec(1, 2, 3)
local b = vec(4, 4, 6)
print(b - a, a, b) -- {3, 2, 3} {1, 2, 3} {4, 4, 6}
With a vector and a number
Returns a new vector of the same size containing the result of subtracting the number from all components of the vector.
Left | Right | Result |
---|---|---|
Vector | number | new Vector |
With a number and a vector
Returns a new vector of the same size containing the result of negating all of the components of the vector, then adding the number. In effect, number - vector == (-vector) + number
.
Left | Right | Result |
---|---|---|
number | Vector | new Vector |
* (operator)
With two vectors
Returns a new vector of the same size containing the result of multiplying the vectors together (component multiplication.)
Left | Right | Result |
---|---|---|
Vector | Vector | new Vector |
With a vector and a number
Returns a new vector of the same size containing the result of scaling the vector by the number (scalar multiplication.)
Left | Right | Result |
---|---|---|
Vector | number | new Vector |
number | Vector | new Vector |
With a vector and a matrix
Returns a new vector of the same size containing the result of transforming the vector with the matrix.
Left | Right | Result |
---|---|---|
Vector | Matrix | new Vector |
/ (operator)
With two vectors
Returns a new vector of the same size containing the result of dividing the left vector by the right vector (component division.)
Left | Right | Result |
---|---|---|
Vector | Vector | new Vector |
With a vector and a number
Returns a new vector of the same size containing the result of scaling the vector by the reciprocal of the number.
Left | Right | Result |
---|---|---|
Vector | number | new Vector |
# (operator)
Returns the number of components in this vector.
Operand | Result |
---|---|
Vector | number |
< (operator)
Returns true
if all of the components of the left vector are strictly less than the corresponding components of the right vector.
Left | Right | Result |
---|---|---|
Vector | Vector | boolean |
local A = vec(1, 2, 3)
local B = vec(4, 5, 6)
local C = vec(4, 1, 6)
print(A < B) -- true
print(B < C) -- false
<= (operator)
Returns true
if all of the components of the left vector are strictly less than or equal to the corresponding components of the right vector.
Left | Right | Result |
---|---|---|
Vector | Vector | boolean |
local A = vec(1, 2, 3)
local B = vec(4, 5, 6)
local C = vec(1, 2, 3)
print(A <= B) -- true
print(B <= C) -- true
tostring return value
Converts the vector to a string representing its components.
Operand | Result |
---|---|
Vector | string |