使用Mathematica中的Graphics在对象内均匀分布点

时间:2011-06-28 16:03:03

标签: graphics wolfram-mathematica point

考虑:

preferred ={{1, 1, 63}, {2, 1, 44}, {3, 1, 27}, {4, 1, 33}, {5, 1, 33}}

frmWidth  =                 20.9067;
frmHeight =                   15.68;

我正在显示5种类型的刺激2乘2.受试者必须选择他们喜欢的刺激。每种类型的刺激都会显示80次:

{1,1,63}表示刺激Cond 1在显示的80倍中优选63次。 {3,1,27}表示刺激Cond 3优于其显示的80倍中的27倍。

Cond1指的是屏幕的中心

Cond2指的是左上象限

Cond3指的是右上象限

Cond4指的是左下象限

Cond5指的是右下象限

我想表达这一结果。

这就是我所做的:

Graphics[{
  Black, EdgeForm[{Thin, LightGray}], 
  Rectangle[{-1, -1}, {frmWidth + 1, frmHeight + 1}], 

  PointSize[0.03],
  Yellow,
  Point@Tuples[{Range[0, frmWidth/2, frmWidth/19], 
  Range[0, frmHeight/2, frmHeight/14]}][[;; preferred[[5, 3]]]],

  Red,
  Point@Tuples[{Range[frmWidth/2, frmWidth, frmWidth/19], 
  Range[0, frmHeight/2, frmHeight/14]}][[;; preferred[[4, 3]]]],

  Green,
  Point@Tuples[{Range[frmWidth/2, frmWidth, frmWidth/19], 
  Range[frmHeight/2, frmHeight, frmHeight/14]}][[;; preferred[[3, 3]]]],

  Orange,
  Point@Tuples[{Range[0, frmWidth/2, frmWidth/19], 
  Range[frmHeight/2, frmHeight, frmHeight/14]}][[;; 
  preferred[[2, 3]]]],

  Blue,
  Point@Tuples[{Range[frmWidth/4, 3/4 frmWidth, frmWidth/19], 
  Range[frmHeight/4, 3/4 frmHeight, frmHeight/14]}][[;; 
  preferred[[1, 3]]]]

  }]

enter image description here

问题是矩形逐渐从左到右填充点,而不是点均匀分布。

请考虑以下事项:

Graphics[{

  White, EdgeForm[Thick], 
  Rectangle[{0, 0}, {frmWidth, frmHeight}],

  Orange, Opacity[.5],
  Rectangle[{0, frmHeight/2}, {frmWidth/2, frmHeight}, RoundingRadius -> 3],

  Green,
  Rectangle[{frmWidth/2, frmHeight/2}, {frmWidth, frmHeight},RoundingRadius -> 3],

  Red,
  Rectangle[{frmWidth/2, 0}, {frmWidth, frmHeight/2}, RoundingRadius -> 3],

  Yellow,
  Rectangle[{0, 0}, {frmWidth/2, frmHeight/2}, RoundingRadius -> 3],

  Blue,
  Rectangle[{frmWidth/4, frmHeight/4}, {3/4 frmWidth, 3/4 frmHeight}, RoundingRadius -> 3]
  }]

enter image description here

现在我想用点填充那些边缘圆角矩形,但是密度会改变,而不是填充的矩形部分。

下面是我在PPT中绘制的非常难看的东西:

enter image description here

理想情况下,填充点的形状可以是任何类型。 积分不会重叠。

请让我知道其他想法。

2 个答案:

答案 0 :(得分:3)

好的,试试这个:

Manipulate[ld = Floor[Sqrt[n]];
Graphics[
{{EdgeForm[Dashed], White, 
  Polygon[{{0, 0}, {0, h}, {w, h}, {w, 0}}]},
 Point[Flatten[#, 1] &@
 Table[{x, y}, {x, 0, w, w/ld}, {y, 0, h, h/ld}]] },
PlotRange \[Rule] {{-1, 20}, {-1, 20}}],
{{n, 25}, 10, 100, 1},
{{h, 10}, 5, 20},
{{w, 10}, 5, 20}]

典型配置:

enter image description here

(我给出的代码可让您通过滑块控制盒子的总数和大小)

答案 1 :(得分:0)

鉴于您的矩形相当小,最简单的解决方案是使用

RandomSample[ allPointsInAnObject ]

有点像这样:

Graphics[{Circle[{0, 0}, 11], PointSize[0.02], 
  Point[RandomSample[
    Cases[Outer[List, Range[-11, 11], Range[-11, 11]], {x_, y_} /; 
      x^2 + y^2 <= 11^2, {2}], 50]]}]