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

• To: mathgroup at smc.vnet.net
• Subject: [mg36367] Re: Generating Two Unit Orthogonal Vectors to a 3D Vector
• From: Selwyn Hollis <slhollis at earthlink.net>
• Date: Tue, 3 Sep 2002 01:41:10 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```In my previous post, I proposed

OrthogonalUnitVectors[v:{_, _, _}] :=
With[{u = Which[
(w = {0,v[],-v[]}).w != 0, w,
(w = {v[],0,-v[]}).w != 0, w,
(w = {v[],-v[],0}).w != 0, w ] },
#/Sqrt[#.#]& /@ {u, Cross[u,v]}]

The trouble with this is that w ends up being a global variable. The
only way I see around that is to use Module instead of With. (May as
well put in a Return[\$Failed] too.)

OrthogonalUnitVectors[v:{_, _, _}] :=
Module[{u, w},
u = Which[(w = {0,v[],-v[]}).w != 0, w,
(w = {v[],0,-v[]}).w != 0, w,
(w = {v[],-v[],0}).w != 0, w,
True, Return[\$Failed]];
#/Sqrt[#.#]& /@ {u, Cross[u, v]} ]

----
Selwyn Hollis

```

• Prev by Date: Mathematica 4.2 Benchmarks?
• Next by Date: Re: Generating Two Unit Orthogonal Vectors to a 3D Vector
• Previous by thread: Re: Generating Two Unit Orthogonal Vectors to a 3D Vector
• Next by thread: Re: Generating Two Unit Orthogonal Vectors to a 3D Vector