대학 1학년 미적분학 과정에서 극좌표를 배우는 시간이면 빠짐없이 등장하는 4엽장미 곡선(quadrifolium)을 그려보자.

일반적인 장미 곡선(rose or rhodonea curve)의 극방정식은

       r = a * cos( b theta )
       (단, 여기서 a 와 b 는 상수이고, r 과 theta 는 극좌표)

은 이다. 상수 a 의 값을 변경하면 장미의 크기가 변경되지만, 상수 b의 값을 변경하면 징미 잎의 개수가 변경된다, (특히 b 를 정수로 하면, 잎의 개수는 2b 개이다,) 그러므로 b = 2 로 하면 잎이 4개인 (네잎 클로버 모양의) 4엽장미 곡선(quadrifolium)이다.


즉, 4엽장미 곡선(quadrifolium)의 극방정식은

       r = cos( 2 theta )
       (단, 여기서 r 과 theta 는 극좌표)

이다. 이제 이 곡선을 여러가지 도구

           Mathematica, Maxima, Grapher, Gnuplot, Octave, Matplotlib

들을 이용하여 그리는 명령을 각각 알아보자.

 
* 윈도우 XP 에서 Mathematica 8 을 이용하여 그리기




* Mac OS X Lion  에서 wxMaxima 를 이용하여 4엽장미 곡선 그리기
** wxMaxima 창에서 그리기 명령 입력
    (주의: Mac 의 경우, draw 에 의한 그리기 명령은  옵션에 반드시 terminal=aquaterm 을 넣어주어야 그래프가 그려진다.)



** 위의 명령으로 별도의 창에 그려진 4엽장미 곡선




* Mac OS X Lion 에서 Grapher 를 이용하여 4엽장미 곡선 그리기




* Mac OS X Lion 에서 Gnuplot 을 이용하여 4엽장미 곡선 그리기
** Gnuplot 소스
set term aqua   # for Mac gnuplot
set clip points
unset border
set dummy t,y
unset key
set polar
set samples 1600, 1600
set xzeroaxis linetype 0 linewidth 1.0
set yzeroaxis linetype 0 linewidth 1.0
set zzeroaxis linetype 0 linewidth 1.0
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 "Cardioid"
set trange [ 0.0 : 2*pi ] noreverse nowriteback
set xrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
set yrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
a = 1
b = 2
quadriFolium(teta) = a*cos(b*teta);
plot 0.5, 1, quadriFolium(t)



** Mac OS X Lion 에서 Gnuplot 을 실행시켜서 그리기 명령을 입력한 화면



** 위의 명령으로 Gnuplot 이 그려준 곡선




* 윈도우 XP 에서 Octave 를 이용하여 4엽장미 곡선 그리기
** Octave 소스
a = 1;
b = 2;
t = 0:0.005:2*pi;
polar(t, a*cos(b*t))
axis([-1.5, 1.5, -1.5, 1.5])



** 위의 명령으로 Octave 가 그려준 4엽장미 곡선





* 윈도우 XP 에서 Python 2.7 & Matplotlib 1.0.1 을 이용하여 극방정식의 4엽장미 곡선 그리기
** 파이썬 소스

#!/usr/bin/env python

"""
An example which plots the graph in polar coordinates.
         Plot a cardioid in polar coordinates.
"""
import matplotlib
import numpy as np
from matplotlib.pyplot import figure, show, rc, grid

# radar green, solid grid lines
rc('grid', color='#316931', linewidth=1, linestyle='-')
rc('xtick', labelsize=15)
rc('ytick', labelsize=15)

# force square figure and square axes looks better for polar, IMO
width, height = matplotlib.rcParams['figure.figsize']
size = min(width, height)
# make a square figure
fig = figure(figsize=(size, size))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c')
# ax = fig.add_axes([-2, -2, 2, 2], polar=True, axisbg='#d5de9c')

delta = 0.01
startAngle = 0.0
lastAngle = 2*np.pi
theta = np.arange(startAngle, lastAngle, 0.01)
a = 1
b = 2
r = a*np.cos(b*theta)
ax.plot(theta, r, color='#ee8d18', lw=3)
ax.set_rmax(1.2)
grid(True)

ax.set_title("Quadrifolium", fontsize=16)
show()


 
** 위의 소스를 실행시켜서 그린 곡선

Posted by Scripter
,