대학 1학년 미적분학 시간에 배우는 심장형 곡선(cardioid) 

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

을 여러가지 도구

           Mathematica, Maxima, Grapher, Gnuplot, Octave, Matplotlib

들로 그리는 명령을 각각 알아보자.

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




* 윈도우 XP  에서 wxMaxima 를 이용하여 심장형 곡선 그리기
** wxMaxima 창에서 그리기 명령 입력



** 위의 명령으로 별도의 창에 그려진 심장형 곡선(cardioid)




* Mac OS X Lion 에서 Grapher 를 이용하여 심장형 곡선 그리기




* 윈도우 XP 에서 Gnuplot 을 이용하여 심장형 곡선 그리기
** Gnuplot 소스
set term win   # for Window wgnuplot
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 = 1
Cardioid(teta) = a - b*cos(teta);
plot 0.5, 1, Cardioid(t)



** 윈도우 XP 에서 Gnuplot 을 실행시켜서 그리기 명령을 입력한 화면



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





* 윈도우 XP 에서 Octave 를 이용하여 그리기
** 극방정식의 심장형 곡선 그리기 (Octave 소스)
a = 1;
b = 1;
t = 0:0.005:2*pi;
polar(t, a - b*cos(t))
axis([-2.5, 0.5, -1.5, 1.5])


** Octave 실행 창에서 그리기 명령 입력



** 위의 명령으로 Octave 가 그려준 곡선





* Python 2.7 & Matplotlib 를 이용하여 극방정식의 심장형 곡선 그리기
** 파이썬 소스
#!/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 = 1
r = a - b*np.cos(theta)
ax.plot(theta, r, color='#ee8d18', lw=3)
ax.set_rmax(2.1)
grid(True)

ax.set_title("Cardioid", fontsize=20)
show()


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


 

Posted by Scripter
,