MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

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


David Park wrote:

> 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, here is a solution generating two random vectors:

OrthogonalUnitVectors[v : {_, _, _}] :=
  Module[{r, v1, v2}, r = {Random[], Random[], Random[]}; v1 = Cross[v, r];
    v2 = Cross[v1, v]; {v1/Sqrt[Dot[v1, v1]], v2/Sqrt[Dot[v2, v2]]}]

Test:

v = {Random[], Random[], Random[]}
{0.864587, 0.727747, 0.669729}

{A,B} = OrthogonalUnitVectors[v]
{{0.279985, -0.808701, 0.517311}, {-0.698881, 0.19773, 0.687363}}

Chop[{A.v, B.v, A.B, A.A, B.B}]
{0, 0, 0, 1., 1.}


John


-- _________________________________
John Browne
School of Engineering and Science
Swinburne University of Technology
John Street, Hawthorn, Victoria, Australia
Quantica phone: +613 9431 4007
Quantica fax: +613 9431 0940
Email: jbrowne at swin.edu.au



  • Prev by Date: Re: Resizing Graphics
  • Next by Date: RE: GraphicsArray, scaling and AspectRatio
  • Previous by thread: Generating Two Unit Orthogonal Vectors to a 3D Vector
  • Next by thread: Re: Generating Two Unit Orthogonal Vectors to a 3D Vector