Drawing an Emergent ellipse with a turtle.

筅森魡賤 提交于 2019-12-11 04:45:02

问题


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

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

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?


回答1:


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

 ]
] 

end



来源:https://stackoverflow.com/questions/39647294/drawing-an-emergent-ellipse-with-a-turtle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!