Vector Orthogonality

Finding any Perpendicular Vector
Finding any perpendicular vector to a vector v amounts to finding another vector u, where u != v A perpendicular vector to v can then be found: p = u x v So, in pseudocode, this could look like: if v == [1,0,0] p = [0,1,0] x v else p = [1,0,0] x v

Perpendicular Vector Close to other Vector
If we have a vector v and another vector u, and we want to find the vector p closest to u, that is perpendicular to v, we can use the simplest case of Gram-Schmidt orthogonalization: p = u - (u projected onto v)  = u - (u dot norm(v)) * norm(v) This can be described as the vector from the projected vector to u, which must be perpendicular to v:

/ u  / / / --->---> v   | u projected onto v

/  /|   u - (u onto v)  / | - the closest vector to u that is orthogonal to v /  | ---*--->