cross

taichi_glsl.vector.cross(a, b)

Calculate the cross product of two vectors. The argument can be 2D or 3D. If 3D, the return value is 3D; If 2D, the return value is a scalar. The computation is done in a right-handed coordinate system, i.e.:

cross(vec(1, 0, 0), vec(0, 1, 0)) == vec(0, 0, 1)
cross(vec(1, 0), vec(0, 1)) == 1
Parameters
  • x – Specifies the first of two vectors, can be 2D or 3D.

  • y – Specifies the second of two vectors, can be 2D or 3D.

Returns

The return value can be calculated as summation(a * b).

For example:

a = vec(1, 2, 3)
b = vec(4, 5, 6)
c = cross(a, b)
# c = [2*6 - 5*3, 4*3 - 1*6, 1*5 - 4*2] = [-3, 6, -3]

p = vec(1, 2)
q = vec(4, 5)
r = cross(a, b)
# r = 1*5 - 4*2 = -3