从笛卡尔图到使用Mathematica的极坐标图

500*_*500 8 wolfram-mathematica angle

请考虑:

dalist={{21, 22}, {26, 13}, {32, 17}, {31, 11}, {30, 9}, 
        {25, 12}, {12, 16}, {18, 20}, {13, 23}, {19, 21}, 
        {14, 16}, {14, 22}, {18,22}, {10, 22}, {17, 23}}


ScreenCenter = {20, 15}

FrameXYs = {{4.32, 3.23}, {35.68, 26.75}}

Graphics[{EdgeForm[Thick], White, Rectangle @@ FrameXYs, 
          Black, Point@dalist, Red, Disk[ScreenCenter, .5]}]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我想要做的是为每个点计算它在坐标系中的角度,例如:

在此输入图像描述

上面是Deisred输出,它们是给定特定"角度仓"的点的频率计数.一旦我知道如何计算角度,我应该能够做到这一点.

Sjo*_*ies 12

Mathematica为此目的具有特殊的绘图功能:ListPolarPlot.您需要将x,y对转换为theta,r对,例如如下:

ListPolarPlot[{ArcTan[##], EuclideanDistance[##]} & @@@ (#-ScreenCenter & /@ dalist), 
          PolarAxes -> True, 
          PolarGridLines -> Automatic, 
          Joined -> False, 
          PolarTicks -> {"Degrees", Automatic}, 
          BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold,FontSize -> 12}, 
          PlotStyle -> {Red, PointSize -> 0.02}
]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


UPDATE

根据评论的要求,极坐标直方图可以如下:

maxScale = 100;
angleDivisions = 20;
dAng = (2 \[Pi])/angleDivisions;
Run Code Online (Sandbox Code Playgroud)

一些测试数据:

(counts = Table[RandomInteger[{0, 100}], {ang, angleDivisions}]) // BarChart
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

ListPolarPlot[{{0, maxScale}}, 
    PolarAxes -> True, PolarGridLines -> Automatic, 
    PolarTicks -> {"Degrees", Automatic}, 
    BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, FontSize -> 12}, 
    PlotStyle -> {None}, 
    Epilog -> {Opacity[0.7], Blue, 
               Table[
                 Polygon@
                  {
                   {0, 0}, 
                   counts[[ang + 1]] {Cos[ang dAng - dAng/2],Sin[ang dAng- dAng/2]}, 
                   counts[[ang + 1]] {Cos[ang dAng + dAng/2],Sin[ang dAng+ dAng/2]}
                  },   
                 {ang, 0, angleDivisions - 1}
               ]}
]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

使用Disk扇区代替Polygons的小视觉改进:

ListPolarPlot[{{0, maxScale}}, 
    PolarAxes -> True, PolarGridLines -> Automatic, 
    PolarTicks -> {"Degrees", Automatic}, 
    BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
    FontSize -> 12}, PlotStyle -> {None}, 
    Epilog -> {Opacity[0.7], Blue, 
               Table[
                 Disk[{0,0},counts[[ang+1]],{ang dAng-dAng/2,ang dAng+dAng/2}],       
                 {ang, 0, angleDivisions - 1}
               ]
              }
]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

的"棒"的更清晰的分离是通过添加而获得EdgeForm[{Black, Thickness[0.005]}]Epilog.现在标记环的数字仍然有不必要的小数点跟踪它们.跟随替换的情节/. Style[num_?MachineNumberQ, List[]] -> Style[num // Round, List[]]删除了那些.最终结果是:

在此输入图像描述

上图也可以生成,SectorChart尽管此图主要用于显示数据的宽度和高度,并且对于具有固定宽度扇区并且您想要突出显示方向和数据计数的图不进行微调.那些方向.但它可以通过使用来完成SectorOrigin.问题是我认为一个扇区的中点为其方向编码所以在一个扇区的中间有0度我必须偏移原点\[Pi]/angleDivisions并且在它们旋转时手动指定刻度:

SectorChart[
   {ConstantArray[1, Length[counts]], counts}\[Transpose], 
   SectorOrigin -> {-\[Pi]/angleDivisions, "Counterclockwise"}, 
   PolarAxes -> True, PolarGridLines -> Automatic, 
   PolarTicks -> 
    {
     Table[{i \[Degree] + \[Pi]/angleDivisions, i \[Degree]}, {i, 0, 345, 15}], 
     Automatic
    }, 
   ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], Blue]},
   BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
   FontSize -> 12}
 ]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

情节几乎相同,但它更具互动性(工具提示等).


Ble*_*der 5

这似乎是极坐标系.笛卡尔到极坐标转换公式在同一篇文章中:

在此输入图像描述

这将返回以弧度表示的角度.

  • 要添加到Blender的答案,请使用[`ArcTan`]的两个参数形式(http://reference.wolfram.com/mathematica/ref/ArcTan.html),因为它会自动考虑象限. (5认同)

acl*_*acl 5

这个

N@ArcTan[#[[1]], #[[2]]] & /@ (# - ScreenCenter & /@ dalist)
Run Code Online (Sandbox Code Playgroud)

返回光线ScreenCenter到每个点的角度列表,以弧度为单位,以-pi和pi之间.

也就是说,我假设您想要绘图中每个点与红点之间的角度.

注意使用ArcTan[x,y]而不是ArcTan[y/x]自动选择适当的符号(否则你必须手动完成,如@Blender的回答).