summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/common/vector.lua12
-rw-r--r--doc/lua_api.txt4
2 files changed, 16 insertions, 0 deletions
diff --git a/builtin/common/vector.lua b/builtin/common/vector.lua
index 9a53409fa..782c137d6 100644
--- a/builtin/common/vector.lua
+++ b/builtin/common/vector.lua
@@ -79,6 +79,18 @@ function vector.angle(a, b)
return math.atan2(crossplen, dotp)
end
+function vector.dot(a, b)
+ return a.x * b.x + a.y * b.y + a.z * b.z
+end
+
+function vector.cross(a, b)
+ return {
+ x = a.y * b.z - a.z * b.y,
+ y = a.z * b.x - a.x * b.z,
+ z = a.x * b.y - a.y * b.x
+ }
+end
+
function vector.add(a, b)
if type(b) == "table" then
return {x = a.x + b.x,
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index 2650bfedf..be19d9e3d 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -2517,6 +2517,10 @@ For the following functions, `v`, `v1`, `v2` are vectors,
* Returns in order minp, maxp vectors of the cuboid defined by `v1`, `v2`.
* `vector.angle(v1, v2)`:
* Returns the angle between `v1` and `v2` in radians.
+* `vector.dot(v1, v2)`
+ * Returns the dot product of `v1` and `v2`
+* `vector.cross(v1, v2)`
+ * Returns the cross product of `v1` and `v2`
For the following functions `x` can be either a vector or a number: