3

How could I get the angle in Degree from 0 to 360 from Cartesian coordinate such that :

{1,0}  = 0   Degree
{0,1}  = 90  Degrees
{-1,0} = 180 Degrees
{0,-1} = 270 Degrees

I am having a hard Time with ArcTan to get the angle bet 180 to 359...

Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
500
  • 6,509
  • 8
  • 46
  • 80

3 Answers3

3

Try:

f[x_List] := Mod[ArcTan @@ x /Pi 180 Degree, 360 Degree]

f /@ {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}
(*
 -> {270 \[Degree], 90 \[Degree], 0, 180 \[Degree]}
*)

Edit

As the previous form was criticized upon, here is another way to do the same. Not so easy to follow for my taste:

f = (180 /Pi ArcTan @@ #)~Mod~360 &
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
3

Try this:

CoordinateToDegree[x_?NumberQ, y_?NumberQ] := 
 Rescale[ArcTan[-x, y], {-Pi, Pi}, {360, 0}]

Using ArcTan[-x,y] you will be aligning on the branch cut so you get a continuous function for the angle. Then Rescale maps the range -Pi...Pi to 0...360.

Here is simple Manipulate which demonstrates this solution:

Manipulate[
 Graphics[{
  Orange, Disk[],
  Black, Text[Style[CoordinateToDegree[Cos[t], Sin[t]], "Title"], {Cos[t], Sin[t]}]},
 PlotRange -> 1.4], {t, 0, 2 \[Pi]}]

enter image description here

Arnoud Buzing
  • 15,383
  • 3
  • 20
  • 50
2

I think this works, despite being ugly:

todeg[x_, y_] := If[# < 0, 360 + #, #] &@(N@ArcTan[x, y]/Degree)
acl
  • 6,490
  • 1
  • 27
  • 33