From Cartesian to polar histograms using Mathematica

Think:

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]}] 

enter image description here

What I would like to do is to calculate for each point its angle in the coordinate system, such as:

enter image description here

The above is the Deisred output, this is the frequency reference of a point specified by a particular Angular bin. As soon as I know how to calculate the angle i, I have to do it.

+8
wolfram-mathematica angle
source share
3 answers

For this purpose, Mathematica has a special function: ListPolarPlot . You need to convert the pairs x, y to theta, r pairs, for example, as follows:

 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} ] 

enter image description here


UPDATE

According to the request for comment, polar histograms can be made as follows:

 maxScale = 100; angleDivisions = 20; dAng = (2 \[Pi])/angleDivisions; 

Some test data:

 (counts = Table[RandomInteger[{0, 100}], {ang, angleDivisions}]) // BarChart 

enter image description here

 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} ]} ] 

enter image description here

A slight visual improvement using Disk sectors instead of Polygon s:

 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} ] } ] 

enter image description here

A clearer separation of "bars" is obtained with the addition of EdgeForm[{Black, Thickness[0.005]}] in Epilog . Now the numbers denoting the rings still have an unnecessary decimal point ending them. After a conspiracy with replacement /. Style[num_?MachineNumberQ, List[]] -> Style[num // Round, List[]] /. Style[num_?MachineNumberQ, List[]] -> Style[num // Round, List[]] are deleted. Final result:

enter image description here

The above chart can also be generated using SectorChart , although this chart is mainly designed to display different widths and heights of the data and is not fine-tuned for areas where you have fixed-width sectors and you want to highlight directions and data in these directions. But this can be done using SectorOrigin . The problem is that I believe that the middle of the sector of the code for its direction, in order to have 0 degrees in the middle of the sector, I have to shift the origin by \[Pi]/angleDivisions and specify the checkmarks manually, as they also rotate:

 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} ] 

enter image description here

The plot is almost the same, but it is more interactive (hints, etc.).

+12
source share

It seems to be a polar coordinate system . Formulas for converting Cartesian numbers to polarity in the same article :

enter image description here

This returns the angle in radians.

+5
source share

it

 N@ArcTan[#[[1]], #[[2]]] & /@ (# - ScreenCenter & /@ dalist) 

returns a list of beam angles from ScreenCenter to each point, in radians and between -pi and pi.

That is, I suggested that you need an angle between each point in your plot and the red dot.

Note the use of ArcTan[x,y] , not ArcTan[y/x] , which automatically selects the appropriate character (otherwise you will have to do this manually, as in @Blender's answer).

+5
source share