Difference between revisions of "VectorA:mul"
From ComputerCraft Wiki
Line 1: | Line 1: | ||
+ | {{lowercase}} | ||
+ | {{Function | ||
+ | |name=vector:add | ||
+ | |args=[[vector (API)|vector]] vect | ||
+ | |returns=[[vector (API)|vector]] | ||
+ | |api=vector | ||
+ | |addon=ComputerCraft | ||
+ | |desc=Multiplies a vector with a scalar and returns the resulting vector. | ||
+ | |examples= | ||
+ | {{Example | ||
+ | |desc=Multiplies a vector by a number and prints the resulting vector. | ||
+ | |code=local a = vector.new(1, 2, 3) | ||
+ | local b = 2.5 | ||
+ | |||
+ | local c = a:mul(b) | ||
+ | |||
+ | print(c.x) | ||
+ | print(c.y) | ||
+ | print(c.z) | ||
+ | --2.5 | ||
+ | --5 | ||
+ | --7.5 | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=Code to recreate the function. Gives insight into what the function does. | ||
+ | |code=local a = vector.new(1, 2, 3) | ||
+ | local b = 2 | ||
+ | |||
+ | local c = vector.new((a.x * b), (a.y * b), (a.z * b)) | ||
+ | --c.x = 2 | ||
+ | --c.y = 4 | ||
+ | --c.z = 6 | ||
+ | }} | ||
+ | }} | ||
+ | |||
+ | [[Category:API_Functions]] | ||
+ | |||
+ | |||
Returns the multiplication of the vector by a scalar | Returns the multiplication of the vector by a scalar | ||
Revision as of 12:33, 23 February 2013
Function vector:add | |
Multiplies a vector with a scalar and returns the resulting vector. | |
Syntax | vector:add(vector vect) |
Returns | vector |
Part of | ComputerCraft |
API | vector |
Examples
Example | |
Multiplies a vector by a number and prints the resulting vector. | |
Code |
local a = vector.new(1, 2, 3) local b = 2.5 local c = a:mul(b) print(c.x) print(c.y) print(c.z) --2.5 --5 --7.5 |
Returns the multiplication of the vector by a scalar
Code representation:
local a = vector.new(1, 2, 3) local b = 2 local c = vector.new((a.x * b), (a.y * b), (a.z * b)) --c.x = 2 --c.y = 4 --c.z = 6
Code example:
local a = vector.new(1, 2, 3) local b = 2.5 local c = a:mul(b) print(c.x) print(c.y) print(c.z) --2.5 --5 --7.5