2011-10-01 41 views
1

對於一個實驗,我們在Matlab中生成了一些由8個磁盤組成的圖像。我們限制了磁盤之間以及磁盤和框架之間的最小距離以及磁盤重心(COG)的位置。波紋管與上升降的COG的組合物的一個例子「第三」在Mathematica中尋求目標

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

enter image description here

我想生成Mathematica中那些刺激。以下是我正在處理的元素(特徵和約束)。措施在Cm。這些形狀的重心(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協調極性系統? )。因此,協調製約其銷售成本將位於我可以選擇磁盤協調

angleBin=22.5 

每22.5度極有Mathematica中有用的功能來實現約束下的選擇拋開Selct

我會很想知道是否可以用一個特定的COG位置生成1個合成的封閉公式。

顯然,我需要獲得一個1000個合成物的池。使用36度的「theta約束」,我應該從10個不同的theta酒吧中提取10 * 100的組合物,使它們的COG位於離中心最小或固定的距離處。

enter image description here

請告訴我,如果需要澄清。感謝您的關注。

+3

您可能會發現部分//blog.wolfram。 COM/2011/06/01 /測試你的-subitizing能力/。它是關於生成圖表以測試快速計數能力的。 –

+0

謝謝!確實很棒! – 500

回答

5

這可能會讓你開始。這是一個簡單的拒絕方法,隨機生成圓圈,扔掉不符合要求的樂團。

參數是小號和大號圓圈的大小,數字和半徑,以及最小間距。最後一個用於到邊界的距離和圓之間的距離。我將它的重心加倍到框架約束的中心。顯然這種用法可以通過添加更多參數來推廣。

爲了評估找到可行合奏的可能性,我打印循環中的次數。此外,我還使用了Catch/Throw機制,這個機制並不是真正必需的(我沒有去掉一些實驗的人爲因素)。

---編輯---

以下代碼與我最初發布的內容相比略有變化。它將重心圓與紅色圓圈分開。

爲了處理它位於某個特定角度的約束,可能會產生如下,旋轉以放入正確的角度位置,並重新檢查從圓圈到幀邊界的距離。可能有更聰明的東西不太可能拒絕,同時仍然保持一致性。實際上,我並不確定我所編碼的內容是從允許的配置空間中統一發布的。如果是這樣,旋轉的影響很可能會破壞該財產。 HTTP:

---結束---編輯

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

enter image description here

+0

謝謝Daniel! – 500