用乌龟画一个紧急椭圆. [英] Drawing an Emergent ellipse with a turtle.

查看:122
本文介绍了用乌龟画一个紧急椭圆.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对我可能措辞不佳的有关超级椭圆的问题.

This is an answer to a question posed in the comments in my possibly poorly worded question about super-ellipses.

在Netlogo中很自然地以在其他语言中看起来很奇怪的方式绘制几何形状.

in Netlogo it is natural to draw geometric shapes in ways that may seem strange in other languages.

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

例如题词使乌龟1在乌龟2周围画一个圆[360-gon].我没有调用任何标准的圆公式,但仍然得到了一个圆.

for instance inscribes makes turtle 1 draw a circle [360-gon] around turtle 2. I did not invoke any of the standard circle formulas but still get a circle.

是否有可能在同一个白话语中画一个椭圆,比如说一只乌龟用另外两只乌龟作为焦点在另一只乌龟周围画出一个椭圆(或超椭圆)?

Is it possible to draw an ellipse in this same vernacular with say one turtle drawing an ellipse (or super-ellipse)round two other turtles using them as the foci?

推荐答案

本质上是使椭圆变为椭圆,您可以将海龟航向设置为焦点的加权平均航向并更新每个步骤.它可以一行完成,但那将是一条丑陋的行.

Essentially to make an ellipse you set the turtles heading to the weighted mean heading of the foci and update each step. It could be done in one line but that would be one ugly line.

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 ;; 

 ]
] 

结束

这篇关于用乌龟画一个紧急椭圆.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆