나비 모양의 곡선을 그려주는 극빙정식(polar equation):
           r = exp(cos(t)) - 2*cos(4*t) + (sin(t/12))^5 

[참고] 
  1.  Fay, Temple H. (May 1989). "The Butterfly Curve". Amer. Math. Monthly 96 (5): 442–443. doi:10.2307/2325155. JSTOR 2325155.
  2. SVG 로 만든 나비 곡선



* 윈도우 XP 에서 Mathematica 8 을 이용하여 그린 나비 모양의 곡선:





* 윈도우 XP 에서 Maxima 5.25.0 을 이용하여 극곡선을 그리는 명령





** 위의 명령으로 Maxima 가 별도의 창에 그려준 나비 모양의 곡선



 

* 윈도우 XP 에서 윈도우 용 Gnuplot 을 이용하여 그린 함수의 그래프:
(* 윈도우 용 Gnuplot 다운로드: http://www.tatsuromatsuoka.com/gnuplot/Eng/winbin/ *)

** 나비 모양의 극곡선을 그리는 gnuplot 소스

set term win   # for Window wgnuplot
set clip points
unset border
set dummy t,y
unset key
set polar
set samples 800, 800
set xzeroaxis linetype 0 linewidth 1.000
set yzeroaxis linetype 0 linewidth 1.000
set zzeroaxis linetype 0 linewidth 1.000
set xtics axis in scale 1,0.5 nomirror norotate  offset character 0, 0, 0 autofreq
set ytics axis in scale 1,0.5 nomirror norotate  offset character 0, 0, 0 autofreq
set title "Butterfly"
set trange [ 0.00000 : 12*pi ] noreverse nowriteback
set xrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
set yrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
butterfly(x)=exp(cos(x))-2*cos(4*x)+sin(x/12)**5
plot 1, 2, 3, 4, 5, butterfly(t - pi/2)



** Gnuplot 이 그려준 곡선 





* Mac OS X Lion 에서 Grapher 를 이용하여 그린 나비 모양의 곡선:

 

 

* 윈도우 XP 의 Python 2.7 에 matplotlib 1.0.1 을 (모두 32비트 용으로) 설치하여 파이썬 소스로 그린 나비 모양의 극곡선:

#!/usr/bin/env python

import matplotlib.pyplot as plt
import numpy as np

theta = np.arange(0., 48., 1./360.)*np.pi
r = np.exp(np.cos(theta)) - 2*np.cos(4*theta) + np.sin(theta/12)**5
plt.polar(theta + np.pi/2, r);

plt.thetagrids(range(45, 360, 90));
plt.rgrids(np.arange(1.0, 6.1, 1), angle=0);

plt.show()



(* 위의 소스는 수정 없이 윈도우 7 의 Python 3.2 64bit 에 matplotlib 1.1.0 64bit 를 설치하여 실행해도 된다 *)


 


* 윈도우 XP 에서 Tkinter 를 이용하여 나비 모양의 극곡선을 그리는 파이썬 소스:

#! /usr/local/bin/python    <- The UNIX "pound bang hack" (auch she-bang).
# coding: MS949

#                              auf dem Mac bedeutunglos :-)
#  Filename: butterfly.py
#  ⓒ 1999 by Jorg Kantel
#
#  2011 Modified by PH Kim
#
# See: http://www.schockwellenreiter.de/pythonmania/pybutt.html

import Tkinter
import Canvas
import math    # fur die Sinus- und Kosinus-Funktionen
import sys           # fur sys.exit(0)   
from Tkconstants import *


class Butterfly:
   def __init__(self, master = None):
   self.canvas = Tkinter.Canvas(master, relief = RIDGE, bd = 2, bg = "white",
         width = 400, height = 400)
   self.canvas.pack()
  
   self.button = Tkinter.Button(master, text = " Draw ", command = self.draw)
   # Der Button soll nicht am unteren Rand "kleben", daher werden oben und
   # unten vier Pixel Rand angefugt.
   self.button.pack(side = BOTTOM, pady = 4)

   def draw(self):
   self.canvas.create_oval(160, 160, 240, 240, outline="black", width=1)
   self.canvas.create_oval(120, 120, 280, 280, outline="black", width=1)
   self.canvas.create_oval(80, 80, 320, 320, outline="black", width=1)
   self.canvas.create_oval(40, 40, 360, 360, outline="black", width=1)
   self.canvas.create_oval(0, 0, 400, 400, outline="black", width=1)
   theta  = 0.0
   while theta < 75.39:
       r = math.exp(math.sin(theta)) - 2*math.cos(4*theta) + (math.sin((2*theta - math.pi)/24))**5
       # aus Polarkoordinaten konvertieren:
       x = r*math.cos(theta)
       y =r*math.sin(theta)
       xx = (x*40) + 200  # auf Canvas-Große skalieren
       yy =  400 -  ((y*40) + 200)     # 400 is height of the region (Modified)
       if (theta == 0.0):
       Canvas.Line(self.canvas, xx, yy, xx, yy, fill="blue")
       else:
       Canvas.Line(self.canvas, xOld, yOld, xx, yy, fill="blue")
       self.canvas.update_idletasks()
       xOld = xx
       yOld = yy
       theta = theta + 0.01

   self.button.config(text = " Quit ", command = self.exit)
   self.canvas.update_idletasks()
   self.button.config(text = " Quit ", command = self.exit)

   def exit(self):
   sys.exit(0)

if __name__ == "__main__":
   # Dies ist nur, damit der Titel angezeigt wird ;-)
   root = Tkinter.Tk()
   # root.title("Butterfly Curve")
   root.title("Fay's Butterfly Curve")
 
   # Erzeuge eine neue Instanz unserer Schmetterlingsklasse ...
   butterfly = Butterfly(root)
   # ... und bringe sie zum Laufen.
   root.mainloop()






* 위의 소스를 실행시켜서 그린 나비 모양의 극곡선:




 

Posted by Scripter
,