Find a perpendicular vector with cross
cross(A, B) calculates the cross product of two three-dimensional vectors. The result is perpendicular to both inputs, with direction determined by the right-hand rule and magnitude equal to the area of the parallelogram they span.
Example and interpretation
cross([1, 0, 0], [0, 1, 0]) returns [0, 0, 1]. Reversing the inputs reverses the result, so order matters. The magnitude is zero for parallel vectors. Use norm to measure the output length, and dot to check perpendicularity: the dot product of the cross result with either original vector is zero.
Applications
Cross products produce surface normals in 3D graphics, torque in mechanics, and oriented area in geometry. Normalize the result when only direction is required. For matrix and vector multiplication, use multiply; a cross product is a specific geometric operation, not general multiplication.
Input requirements
Both inputs must represent compatible three-component vectors. Do not use cross for two-dimensional vectors unless you deliberately embed them in 3D with a zero z-component. Check shapes with size, and use subtract to form direction vectors from pairs of points before applying cross.