Skip to content

pymath.cross

Daniel Flassig edited this page Jul 17, 2026 · 1 revision

Cross product of two 3-vectors.

w = pymath.cross(u, v)
Parameter Type Description
u {x, y, z} Left vector
v {x, y, z} Right vector

Return value

Type Description
w A new 3-vector u × v, perpendicular to both u and v.

Notes:

  • Both arguments must be 3-vectors (arrays of length 3) — the cross product is only provided in three dimensions.
  • u and v are not modified.
  • The orientation follows the right-hand rule: pymath.cross({1,0,0}, {0,1,0}) == {0,0,1}.
  • The length of w equals the area of the parallelogram spanned by u and v; for parallel inputs the result is {0, 0, 0} (which pymath.normalize then rejects with nil).

Example:

local n = pymath.cross({1, 0, 0}, {0, 1, 0})
-- n == {0, 0, 1}

-- normal of the triangle (p1, p2, p3)
local u = {p2[1] - p1[1], p2[2] - p1[2], p2[3] - p1[3]}
local v = {p3[1] - p1[1], p3[2] - p1[2], p3[3] - p1[3]}
local normal = pymath.normalize(pymath.cross(u, v))

Version Support:

Minimum PYTHA Version: V27

See also:

pymath, pymath.dot, pymath.normalize, pymath.length

Clone this wiki locally