Арктан Биннинг, от сюжета к гистограмме, хитрости - PullRequest
7 голосов
/ 17 сентября 2011

На основе Sjoerd, отличного решения и расширения на От декартовой диаграммы до полярной гистограммы с использованием Mathematica , пожалуйста, обратите внимание на следующее:

list = {{21, 16}, {16, 14}, {11, 11}, {11, 12}, 
        {13, 15}, {18, 17}, {19, 11}, {17, 16}, {16, 19}}

ScreenCenter = {20, 15}

ListPolarPlot[{ArcTan[##], EuclideanDistance[##]} & @@@ (# - ScreenCenter & /@ list), 
              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

Module[{Countz, maxScale, angleDivisions, dAng},
        Countz = Reverse[BinCounts[Flatten@Map[ArcTan[#[[1]] - ScreenCenter[[1]], #[[2]] - 
                 ScreenCenter[[2]]] &, list, {1}], {-\[Pi], \[Pi], \[Pi]/6}]];
        maxScale = 4;
        angleDivisions = 12;
        dAng = (2 \[Pi])/angleDivisions;

SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose],
             SectorOrigin -> {-\[Pi]/angleDivisions, "Counterclockwise"},
             PolarAxes -> True,
             PolarGridLines -> Automatic,
             PolarTicks -> {Table[{i \[Degree] + \[Pi]/angleDivisions,i \[Degree]}, 
             {i, 0, 345, 30}], Automatic},
             ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], Red]}, 
             BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
             FontSize -> 12}, ImageSize -> 400]]

enter image description here

Как видите, гистограмма показывает вращательную симметрию того, что должно. Я перепробовал все, чтобы разобраться, но безуспешно. Без реверса это хуже всего. Я попробовал RotateRight без успеха. Я чувствую, что проблема в моем BinCount. Выход ArcTan из -Pi в Pi, тогда как Sjoerd предложил мне перейти от 0 до 2Pi. Но я не понимаю, как это сделать.

РЕДАКТИРОВАТЬ: Проблема решена. Благодаря решениям Sjoerd, Belisarius, Heike, я могу показать гистограмму местоположений фиксации глаза с учетом центра тяжести изображения.

enter image description here

Ответы [ 2 ]

6 голосов
/ 18 сентября 2011

Просто проверяю прямо сейчас, но ваш первый сюжет кажется некорректным:

list = {{21, 16}, {16, 14}, {11, 11}, {11, 12}, {13, 15}, 
        {18, 17}, {19, 11}, {17, 16}, {16, 19}};
ScreenCenter = {20, 15};

Show[ListPlot[list, PlotStyle -> Directive[PointSize[Medium], Purple]], 
     Graphics[
              {Red, PointSize[Large], Point[ScreenCenter], 
               Circle[ScreenCenter, 10]}], 
AspectRatio -> 1, Axes -> False]

enter image description here

ListPolarPlot[{ArcTan[Sequence @@ ##], Norm[##]} &/@ (#-ScreenCenter & /@ list), 
 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

Редактировать

Я не следовал всему вашему коду, но отражение в Центре экрана, кажется, исправляет ситуацию:

Module[{Countz, maxScale, angleDivisions, dAng}, 
 Countz = BinCounts[
               {ArcTan[Sequence @@ ##]} & /@ (# + ScreenCenter & /@ -list), 
           {-Pi, Pi, Pi/6}];
 maxScale = 4;
 angleDivisions = 12;
 dAng = (2 Pi)/angleDivisions;

 SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose], 

  SectorOrigin -> {-Pi/angleDivisions, "Counterclockwise"}, 
  PolarAxes -> True, 
  PolarGridLines -> Automatic, 
  PolarTicks -> {Table[{i \[Degree] + Pi/angleDivisions, 
                        i \[Degree]}, {i, 0, 345, 30}], Automatic}, 
  ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], Red]},
   BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
    FontSize -> 12}, 
   ImageSize -> 400]]

enter image description here

Изменить

Здесь вы можете увидеть небольшое смещение в моем коде, которое решается в ответе Хайке (проголосуйте за него!)

Show[Module[{Countz, maxScale, angleDivisions, dAng}, 
  Countz = BinCounts[{ArcTan[
        Sequence @@ ##]} & /@ (# + 
         ScreenCenter & /@ -list), {-\[Pi], \[Pi], \[Pi]/6}];
  maxScale = 4;
  angleDivisions = 12;
  dAng = (2 \[Pi])/angleDivisions;
  SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose], 
   SectorOrigin -> {-\[Pi]/angleDivisions, "Counterclockwise"}, 
   PolarAxes -> True, PolarGridLines -> Automatic, 
   PolarTicks -> {Table[{i \[Degree] + \[Pi]/angleDivisions, 
       i \[Degree]}, {i, 0, 345, 30}], Automatic}, 
   ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], 
      Red]}, BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, 
     FontSize -> 12}, ImageSize -> 400]],
 ListPlot[Plus[# - ScreenCenter] & /@ list/2.5, 
  PlotMarkers -> Image[CrossMatrix[10], ImageSize -> 10]]
 ]

enter image description here

5 голосов
/ 18 сентября 2011

Вы можете использовать опцию ChartElementFunction для точного позиционирования секторов.Первый аргумент ChartElementFunction имеет форму {{angleMin, angleMax}, {rMin,rMax}}.Первый сектор имеет границы {angleMin, angleMax} = {-Pi/12, Pi/12}, второй {Pi/12, 3 Pi/12} и т. Д. Поэтому, чтобы получить правильное вращение, вы можете сделать что-то вроде

Module[{Countz, maxScale, angleDivisions, dAng},
 maxScale = 4;
 angleDivisions = 12;
 dAng = (2 \[Pi])/angleDivisions;
 Countz = BinCounts[
   Flatten@Map[ArcTan @@ (# - ScreenCenter) &, list, {1}], 
    {-Pi, Pi, dAng}];

 SectorChart[{ConstantArray[1, Length[Countz]], Countz}\[Transpose], 
  SectorOrigin -> {-\[Pi]/angleDivisions, "Counterclockwise"}, 
  PolarAxes -> True, PolarGridLines -> Automatic, 
  PolarTicks -> {Table[{i \[Degree] + \[Pi]/angleDivisions, 
      i \[Degree]}, {i, 0, 345, 30}], Automatic}, 
  ChartStyle -> {Directive[EdgeForm[{Black, Thickness[0.005]}], Red]},
  BaseStyle -> {FontFamily -> "Arial", FontWeight -> Bold, FontSize -> 12}, 
  ImageSize -> 400,

  ChartElementFunction -> 
   Function[{range}, Disk[{0, 0}, range[[2, 2]], - 11 Pi/12 + range[[1]]]]]]

enter image description here

...