1

对于一个实验,我们在 Matlab 中生成了一些由 8 个磁盘组成的图像。我们限制了磁盘之间以及磁盘与框架之间的最小距离以及磁盘重心 (COG) 的位置。下面是一个组合示例,其中 COG 位于上部升降机“第三”处

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

stiDisks = {{{8, 11}, 1}, {{10, 17}, 1}, {{16, 24}, 1}, {{25, 22},1}, 
           {{31, 22}, 1}, {{7, 21}, 2}, {{16, 12}, 2}, {{19, 22}, 2}}

Graphics[{White, EdgeForm[Thick],
  Rectangle @@ FraXYs,
  Red, Disk[{14.77, 18.91}, 1],
  Blue, Opacity[.6], EdgeForm[Black],
  Blue, Thickness[0.003],
  Opacity[1],
  Black,
  Disk[#[[1]], #[[2]]] & /@ stiDisks}, ImageSize -> {400, 300}]

在此处输入图像描述

我想在 Mathematica 中产生这些刺激。以下是我正在处理的元素(特征和约束)。度量单位为厘米。形状的重心 (COG) 定义为圆盘的面积加权位置。

特点 :

刺激帧: {{xMin,xMin},{xMax,yMax}}

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

5 个小圆盘:带半径

rSmall=1

3 个大圆盘:带半径

rLarge=2

约束:

形状边缘之间的最小距离:

minDistSha=1

形状边缘和框架边框之间的最小距离:

minDistFra=1

形状 COG 到中心的距离:

minDistCogCenter=2

潜在地,我需要将磁盘的 COG 限制为与中心成一定角度(极坐标系中的 theta 坐标?)。所以我可以选择磁盘坐标,将它们的 COG 限制为在极坐标中每 22.5 度定位一次

angleBin=22.5

Mathematica 中是否有有用的函数来实现在约束条件下的选择Selct

我很想知道是否可以使用封闭公式生成具有特定 COG 位置的 1 个组合。

指示性地,我需要获得 1000 首作品。使用 36 度的“theta 约束”,我应该提取 10*100 的构图,其 COG 位于距中心最小或固定距离的 10 个不同的 theta 条上。

在此处输入图像描述

请告诉我是否需要澄清。感谢您的关注。

4

1 回答 1

5

这可能会让你开始。这是一种简单的拒绝方法,随机生成圆圈,丢弃不符合要求的集合。

参数是盒子的大小、小圆和大圆的数量和半径,以及最小间隔。最后一个用于到边界的距离和圆之间的距离。我将重心加倍到框架约束的中心。显然,可以通过添加更多参数来推广这种用法。

为了评估找到可行集成的可能性有多大,我打印了循环的次数。此外,我使用了一种并非真正需要的 Catch/Throw 机制(一些实验的产物,我没有费心去移除)。

- - 编辑 - -

下面的代码与我最初发布的代码相比有适度的变化。它将重心圈分隔为红色。

为了处理它位于某个指定角度的约束,可以生成如下,旋转以放入正确的角度位置,并重新检查从圆到框架边界的距离。可能有一些更聪明的东西不太可能拒绝,同时仍然保持一致性。实际上,我完全不确定我编码的内容是否从允许的配置空间中给出了均匀分布。如果是这样,旋转的影响很可能会破坏该属性。

--- 结束编辑 ---

randomConfiguration[{xlo_, ylo_}, {xhi_, yhi_}, nsmall_, nlarge_, 
  rsmall_, rlarge_, minsep_] := Catch[Module[
   {found = False, xsmall, ysmall, xlarge, ylarge, smallsep, largesep,
     smallcircs, largecircs, cog, cen, indx = 0},
   smallsep = {rsmall + minsep, -rsmall - minsep};
   largesep = {rlarge + minsep, -rlarge - minsep};
   cen = {xhi - xlo, yhi - ylo};
   While[! found,
    found = True;
    indx++;
    xsmall = RandomReal[{xlo, xhi} + smallsep, nsmall];
    ysmall = RandomReal[{ylo, yhi} + smallsep, nsmall];
    xlarge = RandomReal[{xlo, xhi} + largesep, nlarge];
    ylarge = RandomReal[{ylo, yhi} + largesep, nlarge];
    smallcircs = Transpose[{xsmall, ysmall}];
    Do[If[
      Norm[smallcircs[[i]] - smallcircs[[j]]] <= 2*rsmall + minsep, 
      found = False; Break[]], {i, nsmall - 1}, {j, i + 1, nsmall}];
    largecircs = Transpose[{xlarge, ylarge}];
    Do[If[
      Norm[largecircs[[i]] - largecircs[[j]]] <= 2*rlarge + minsep, 
      found = False; Break[]], {i, nlarge - 1}, {j, i + 1, nlarge}];
    Do[If[
      Norm[smallcircs[[i]] - largecircs[[j]]] <= 
       rsmall + rlarge + minsep, found = False; Break[]], {i, 
      nsmall}, {j, nlarge}];
    cog = (rsmall^2*Total[smallcircs] + 
        rlarge^2*Total[largecircs])/(nsmall*rsmall^2 + 
        nlarge*rlarge^2);
    If[Norm[cog - cen] <= 2*minsep, found = False;];
    ];
   Print[indx];
   Throw[{{cog, rsmall},Map[{#, rsmall} &, smallcircs], 
     Map[{#, rlarge} &, largecircs]}]
   ]]

例子:

{smallc, largec} = 
  randomConfiguration[{4.32, 3.23}, {35.68, 26.75}, 5, 3, 1, 2, 1];

13

FraXYs = {{4.32, 3.23}, {35.68, 26.75}};

{cog, smallc, largec} = 
  randomConfiguration[{4.32, 3.23}, {35.68, 26.75}, 5, 3, 1, 2, 1];

Graphics[{White, EdgeForm[Thick], Rectangle @@ FraXYs, Red, 
  Apply[Disk, cog], Blue, Opacity[.6], EdgeForm[Black], Blue, 
  Thickness[0.003], Opacity[1], Black, 
  Disk[#[[1]], #[[2]]] & /@ Join[smallc, largec]}, 
 ImageSize -> {400, 300}]

在此处输入图像描述

于 2011-10-02T21:23:27.163 回答