3차원 직교좌표계에서 구면(sphere)의 매개방정식은
\, x = x_0 + r \sin \theta \; \cos \varphi
\, y = y_0 + r \sin \theta \; \sin \varphi \qquad (0 \leq \varphi \leq 2\pi \mbox{ and } 0 \leq \theta \leq \pi ) \,
\, z = z_0 + r \cos \theta \,

으로 주어진다. 이 매개방정식을 이용하여 구면을 여러가지 그리기 도구

          Mathemarica, Maxima, Grapher, Gnuplot, Octave, Matplotlib

들로 각각 그려보자.        



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





* 윈도우 XP 에서 wxMaxima 를 이용하여 그리기
** 명령 입력



** 위의 명령으로 별도의 창에 그려진 곡면





* Mac OS X Lion 에서 Grapher 를 이용하여 그리기





* 윈도우 XP 에서 Gnuplot 을 이용하여 그리기
** Gnuplot 소스

#
# parametricSphere.dem

set term win
set parametric
set isosamples 80, 30
set hidden
set key below

set title "Parametric Sphere"
set urange [0:2*pi]
set vrange [-pi/2:pi/2]
set ztics nomirror -2.0, 0.5, 2.0
set view 45,50
a = 3
splot a*cos(u)*cos(v), a*sin(u)*cos(v), a*sin(v)



** Gnuplot 창에 위의 소스를 입력하기



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




* 윈도우 XP 에서 Octave 3.2.4 를 이용하하여 곡면 그리기
** Octave 소스
a = 3;
x = @(u, v) a.*cos (u) .* cos(v);
y = @(u, v) a.*sin (u) .* cos(v);
z = @(u, v) a.*sin(v);
ezmesh (x, y, z, [0, 2*pi, -pi/2, pi/2], 50);


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




* Matplotlib 를 이용하여 곡면 그리기
** 파이썬 소스
#!/usr/bin/env python

from mpl_toolkits.mplot3d.axes3d import Axes3D
import matplotlib.pyplot as plt

# imports specific to the plots in this example
import numpy as np
from matplotlib import cm

# Twice as wide as it is tall.
fig = plt.figure(figsize=plt.figaspect(0.7))

#---- First subplot
ax = fig.add_subplot(1, 1, 1, projection='3d')
U = np.arange(0, 2*np.pi, 0.1)
V = np.arange(0, 2*np.pi, 0.1)
U, V = np.meshgrid(U, V)
a = 3
X = a*np.cos(U)*np.cos(V)
Y = a*np.sin(U)*np.cos(V)
Z = a*np.sin(V)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
        linewidth=0, antialiased=False)
ax.set_zlim3d(-2.01, 2.01)

fig.colorbar(surf, shrink=0.5, aspect=10)

plt.show()




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




 

Posted by Scripter
,