Skip to content

Commit 71db715

Browse files
HybridDogsfan5
authored andcommittedJul 16, 2019
Add vector.dot and vector.cross
Mostly copied from MarkuBu's code
1 parent 458f617 commit 71db715

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
 

Diff for: ‎builtin/common/vector.lua

+12
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ function vector.angle(a, b)
7979
return math.atan2(crossplen, dotp)
8080
end
8181

82+
function vector.dot(a, b)
83+
return a.x * b.x + a.y * b.y + a.z * b.z
84+
end
85+
86+
function vector.cross(a, b)
87+
return {
88+
x = a.y * b.z - a.z * b.y,
89+
y = a.z * b.x - a.x * b.z,
90+
z = a.x * b.y - a.y * b.x
91+
}
92+
end
93+
8294
function vector.add(a, b)
8395
if type(b) == "table" then
8496
return {x = a.x + b.x,

Diff for: ‎doc/lua_api.txt

+4
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,10 @@ For the following functions, `v`, `v1`, `v2` are vectors,
25172517
* Returns in order minp, maxp vectors of the cuboid defined by `v1`, `v2`.
25182518
* `vector.angle(v1, v2)`:
25192519
* Returns the angle between `v1` and `v2` in radians.
2520+
* `vector.dot(v1, v2)`
2521+
* Returns the dot product of `v1` and `v2`
2522+
* `vector.cross(v1, v2)`
2523+
* Returns the cross product of `v1` and `v2`
25202524

25212525
For the following functions `x` can be either a vector or a number:
25222526

0 commit comments

Comments
 (0)
Please sign in to comment.