2016-09-22 45 views
1

這是對我在可能措辭不佳的question關於超橢圓的評論中提出的問題的回答。用烏龜繪製一個緊急橢圓。

在Netlogo中,以其他語言看起來很奇怪的方式繪製幾何形狀是很自然的。

ask turtle 1 [pendown 
       let d (pi * distance turtle 2)/360 
       repeat 360 [face turtle 2 rt 90 fd d] 
      ] 

例如題讓龜1畫了一個圈[360坤]龜左右2.我沒有調用任何標準的圓式,但仍得到一個圓。

是否有可能在這個相同的白話中繪製一個橢圓,並說一個烏龜畫一個橢圓(或超橢圓)圍繞另外兩個烏龜使用它們作爲焦點?

回答

2

基本上要製作一個橢圓形,您需要設置朝向焦點加權平均標題的龜,並更新每個步驟。它可以在一行中完成,但那將是一條不合格的路線。

globals [a b c] 
    to setup 
     ca 
     crt 1 [set heading 90 fd 10 pendown set C self] 
     crt 1 [setxy 5 10 set A self] 
     crt 1 [setxy 0 -10 set B self] 
    end 

to go 

repeat 5100 ;; ad hoc number 
[ 
ask c 
[ 
let Ax [xcor] of A - xcor 
let Ay [ycor] of A - ycor 
let Bx [xcor] of B - xcor 
let By [ycor] of B - ycor 
let da 1/distance a 
let db 1/distance B 

set heading 90 + atan ((ax * da + bx * dB)/(da + db)) 
         ((ay * da + by * db)/(da + db)) 
FD .0125 ;; 

] 
]