Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

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





  • 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