Re:Generating Two Unit Orthogonal Vectors to a 3D Vector

*To*: mathgroup at smc.vnet.net*Subject*: [mg36373] Re:Generating Two Unit Orthogonal Vectors to a 3D Vector*From*: Goyder Dr HGD <H.Goyder at rmcs.cranfield.ac.uk>*Date*: Wed, 4 Sep 2002 02:56:27 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

There are many cases in graphics, and otherwise, where it is useful to obtain two orthogonal unit vectors to a given vector. I know a number of ways to do it, but they all seem to be slightly inelegant. I thought I would pose the problem to MathGroup. Who has the most elegant Mathematica routine... OrthogonalUnitVectors::usage = "OrthogonalUnitVectors[v:{_,_,_}] will return two unit vectors orthogonal to each other and to v." You can assume that v is nonzero. David Park David, My suggestion In[1]:= << "LinearAlgebra`Orthogonalization`" In[2]:= OrthogonalUnitVectors[v:{_, _, _}] := GramSchmidt[NullSpace[{v}]] In[3]:= v = {1, 2, 3}; {v1, v2} = OrthogonalUnitVectors[v] Out[4]= {{-(3/Sqrt[10]), 0, 1/Sqrt[10]}, {-(1/Sqrt[35]), Sqrt[5/7], -(3/Sqrt[35])}} In[5]:= {v . v1, v . v2, v1 . v2, v1 . v1, v2 . v2} Out[5]= {0, 0, 0, 1, 1} Also works with symbolic expressions Hugh Goyder