2016-09-20 133 views
0

显然,任何可以用其他方式绘制的形状都可以由海龟绘制。圆形和方形容易用海龟绘制超椭圆形

rt 1 fd .0 

if ticks mod 100 = 0 [rt 90] 
fd 1 

超椭圆没有这么多。 (正则省略也不是微不足道的。) The Wikipedia article on super-ellipses如果您需要刷新主题。

任何输入表示赞赏。

使用倒吊的乌龟是否有办法使乌龟运动中出现超椭圆?

+0

你说定期的省略号不是微不足道的,你知道它们是如何绘制的吗? – gue

+0

很喜欢lon的答案。 –

+0

使用setpos做什么问题?你有方程。 –

回答

1

我有它的1/4,我想你可以将其他三个拼在一起。这里没有测试n的其他值。 (使用Wiki标记,加上phi作为旋转整个事物的一个角度)。我知道,重置刻度的位置是笔直的,笔直下降。

to go2 
    clear-all 
    reset-ticks 
    let a 6 
    let b 5 
    let phi 0 
    let n 3.5 
    create-turtles 1 [ 
    let iNdx 1 
    repeat 90 [ 
     show iNdx 
     show cos(iNdx) 
     if cos(iNdx) > 0 and sin(iNdx) > 0 [ 
     let tx (a * (cos(iNdx)^(2/n))) 
     let ty (b * (sin(iNdx)^(2/n))) 
     let tx2 tx * cos(phi) - ty * sin(phi) 
     let ty2 tx * sin(phi) + ty * cos(phi) 
     setxy tx2 ty2 
     ] 
     pen-down 
     set iNdx iNdx + 1 
     ] 
    ] 
    end 

椭圆看起来简单,但你是法官

to go 
    clear-all 
    reset-ticks 
    let a 6 
    let b 5 
    let phi 45 
    create-turtles 1 [ 

    let iNdx 1 
    repeat 360 [ 
     let tx (a * cos(iNdx)) 
     let ty (b * sin(iNdx)) 
     let tx2 tx * cos(phi) - ty * sin(phi) 
     let ty2 tx * sin(phi) + ty * cos(phi) 
     setxy tx2 ty2 
     pen-down 
     set iNdx iNdx + 1 
     ] 
    ] 
    end 

一个概括和简化的程序。

to Super-ellipse [x y a b m n] 
create-turtles 1 [ 
let iNdx 1 
repeat 360 [ 
setxy (x + (abs cos iNdx)^(2/m) * a * (sgn cos iNdx)) 
     (y + (abs sin iNdx)^(2/n) * b * (sgn sin iNdx)) 
pendown 
set iNdx iNdx + 1] 
] 
end 
+0

Very很好,我搞砸了一下,并做了一个使你的许可完整的椭圆,我将它添加到你的答案。 –

+0

你好。我的答案尖叫改进! –

+0

我添加了它并删除了我的竞争答案。 –

0

另一个答案的广义形式似乎产生了我想到的那种东西。笔开始越靠近其中一个焦点,画图越接近正方形。没有实现超椭圆。

globals[c] 
breed [pens pen] 
breed [foci focus] 
foci-own [dist distx disty] 
to setup 
ca 
create-pens 1 [set heading 45 fd 10 pendown set C self] 
;create-foci 1 [setxy (random-xcor/2) (random-ycor/2)] 
create-foci 1 [setxy 10 10] 
create-foci 1 [setxy 10 -10] 
create-foci 1 [setxy -10 -10] 
create-foci 1 [setxy -10 10] 
end 

to go 
repeat 5100 
    [ 
    ask foci [ 
      set dist distance c 
      set distx xcor - [xcor] of c 
      set disty ycor - [ycor] of c 
     ] 
ask c 
[ 
     set heading 90 + atan (sum [distx/dist] of foci/sum [dist] of foci) 
         (sum [disty/dist] of foci/sum [dist] of foci) 
     FD .0125 
    ] 
    ] 
end