Xah Lee wrote:
«
...
“Ignorance And Intolerance In Online Computing Communities”
http://xahlee.org/Netiquette_dir/ignorance_intolerance.html

...  As i have indicated in my post, it is non-trivial to implement a
function that returns the positive angle of a vector....
»

I have now coded this. I think it is probably the most algorithmically
optimal, and rather much simpler than i originally thought. Here's the
Mathematica code:

vectorAngle[{a1_, a2_}] := Module[{x, y},
    {x, y} = {a1, a2}/Sqrt[a1^2 + a2^2] // N;
    If[x == 0 && y == 0, "fucked",
      If[x == 0, [EMAIL PROTECTED] === 1, π/2, -π/2],
        If[y == 0, [EMAIL PROTECTED] === 1, 0, π],
          [EMAIL PROTECTED] === 1, [EMAIL PROTECTED], 2 π - [EMAIL PROTECTED]
          ]
        ]
      ]
    ]

Btw, if we can use any Mathematica's buildin function, this is
actually just
vectorAngle2[{a1_, a2_}] := Arg@(Complex @@ {a1, a2})

I'm still interested, if someone would show the source code, of how
Perl, Python, or Lisp or Java, implement the function that finds the
angle of a complex number.

Originally, i was also hoping perhaps there's some math trick by dot
product or combination of trig functions, that obviates the need to
check which quadrant the vector is in ...

  Xah
  [EMAIL PROTECTED]
∑ http://xahlee.org/

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to