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[[3]],-v[[2]]}).w != 0, w, (w = {v[[3]],0,-v[[1]]}).w != 0, w, (w = {v[[2]],-v[[1]],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[[3]],-v[[2]]}).w != 0, w, (w = {v[[3]],0,-v[[1]]}).w != 0, w, (w = {v[[2]],-v[[1]],0}).w != 0, w, True, Return[$Failed]]; #/Sqrt[#.#]& /@ {u, Cross[u, v]} ] ---- Selwyn Hollis