ignorance and intolerance in computing communties

Xah Lee xah at xahlee.org
Thu May 3 10:49:33 EDT 2007


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, If[Sign at y === 1, π/2, -π/2],
        If[y == 0, If[Sign at x === 1, 0, π],
          If[Sign at y === 1, ArcCos at x, 2 π - ArcCos at x]
          ]
        ]
      ]
    ]

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
  xah at xahlee.orghttp://xahlee.org/




More information about the Python-list mailing list