• R/O
  • SSH

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修訂a504100084ef6dda386173ca6623e7572885f224 (tree)
時間2014-01-05 07:32:30
作者Lorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

A code for visualizing the spherical harmonics with MayaVi2.

Change Summary

差異

diff -r 7cbd25cc7b99 -r a504100084ef Python-codes/spherical_harmonics.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Python-codes/spherical_harmonics.py Sat Jan 04 23:32:30 2014 +0100
@@ -0,0 +1,52 @@
1+"""
2+Plot spherical harmonics on the surface of the sphere, as well as a 3D
3+polar plot.
4+
5+This example requires scipy.
6+
7+In this example we use the mlab's mesh function:
8+:func:`mayavi.mlab.mesh`.
9+For plotting surfaces this is a very versatile function. The surfaces can
10+be defined as functions of a 2D grid.
11+
12+For each spherical harmonic, we plot its value on the surface of a
13+sphere, and then in polar. The polar plot is simply obtained by varying
14+the radius of the previous sphere.
15+"""
16+
17+# Author: Gael Varoquaux <gael.varoquaux@normalesup.org>
18+# Copyright (c) 2008, Enthought, Inc.
19+# License: BSD Style.
20+
21+from mayavi import mlab
22+import numpy as np
23+from scipy.special import sph_harm
24+
25+# Create a sphere
26+r = 0.3
27+pi = np.pi
28+cos = np.cos
29+sin = np.sin
30+phi, theta = np.mgrid[0:pi:101j, 0:2*pi:101j]
31+
32+x = r*sin(phi)*cos(theta)
33+y = r*sin(phi)*sin(theta)
34+z = r*cos(phi)
35+
36+mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(400, 300))
37+mlab.clf()
38+# Represent spherical harmonics on the surface of the sphere
39+for n in range(1, 6):
40+ for m in range(n):
41+ s = sph_harm(m, n, theta, phi).real
42+
43+ mlab.mesh(x-m, y-n, z, scalars=s, colormap='jet')
44+
45+ s[s<0] *= 0.97
46+
47+ s /= s.max()
48+ mlab.mesh(s*x-m, s*y-n, s*z+1.3, scalars=s, colormap='Spectral')
49+
50+mlab.view(90, 70, 6.2, (-1.3, -2.9, 0.25))
51+mlab.show()
52+