Wolfram mathematica 从坐标到度

Wolfram mathematica 从坐标到度,wolfram-mathematica,coordinates,Wolfram Mathematica,Coordinates,如何从笛卡尔坐标获得0到360度的角度,以便: {1,0} = 0 Degree {0,1} = 90 Degrees {-1,0} = 180 Degrees {0,-1} = 270 Degrees 我很难在ArcTan获得180到359的角度下注…试试: f[x_List] := Mod[ArcTan @@ x /Pi 180 Degree, 360 Degree] f /@ {{0, -1}, {0, 1}, {1, 0}, {-1, 0}} (* -> {270

如何从笛卡尔坐标获得0到360度的角度,以便:

{1,0}  = 0   Degree
{0,1}  = 90  Degrees
{-1,0} = 180 Degrees
{0,-1} = 270 Degrees
我很难在ArcTan获得180到359的角度下注…

试试:

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]}
*)
编辑

正如前一种形式受到批评一样,这里有另一种方法来做同样的事情。就我的口味而言,不太容易理解:

f = (180 /Pi ArcTan @@ #)~Mod~360 &

我认为这是可行的,尽管很难看:

todeg[x_, y_] := If[# < 0, 360 + #, #] &@(N@ArcTan[x, y]/Degree)
todeg[x,y]:=If[#<0,360+#,#]&@(N@ArcTan[x,y]/度)
试试这个:

CoordinateToDegree[x_?NumberQ, y_?NumberQ] := 
 Rescale[ArcTan[-x, y], {-Pi, Pi}, {360, 0}]
使用
ArcTan[-x,y]
将在支管切口上对齐,以便获得角度的连续函数。然后,
Rescale
将范围
-Pi…Pi
映射到
0…360

下面是简单的
操作
,它演示了此解决方案:

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

你为什么用
f[#]&
而不是
f
?@Sza像往常一样,我尝试了几种替代方法,但忘记了清理代码:)你为什么用
ArcTan[Sequence@@x]
而不是
ArcTan@@x
?@Sjoerd因为我认为OPI更容易理解,我会说你让它更复杂。第一种形式究竟怎么会比第二种更简单呢?