1
## Automatically adapted for scipy Oct 31, 2005 by
3
# Copyright (c) 1996, 1997, The Regents of the University of California.
4
# All rights reserved. See Legal.htm for full text and disclaimer.
11
from numpy.core.umath import *
13
from arrayfns import *
16
i = raw_input ("Type in any string to continue; ^C to return to prompt. ")
20
x = span (-1, 1, 64, 64)
22
z = (x + y) * exp (-6.*(x*x+y*y))
24
if len (i) == 0 or i [0] == 1 :
25
s1 = Surface (z = z, opt_3d = "wm", mask = "sort")
27
g1 = Graph3d (s1, color_card = "gray.gp", titles = "opaque wire mesh", y_factor = 2.)
33
s1.set (mask = "none")
35
g1.change (titles = "transparent wire mesh")
39
s1.set (ecolor = "red")
40
g1.change (titles = "transparent wire mesh in red")
44
s1.set (mask = "sort", shade = 1)
45
g1.change (titles = "opaque shaded mesh with red lines")
49
s1.set (opt_3d = "none")
50
g1.change (titles = "opaque shaded mesh with no lines")
54
g1.change (titles = "same with different lighting")
55
g1.quick_plot (diffuse=.1, specular = 1., sdir=array([0,0,-1]))
58
s1.set (c = z - min (ravel (z)), opt_3d = "s4", shade = 0)
59
g1.change (color_card = "rainbow.gp",
60
titles = "surface shaded according to height")
64
if len (i) == 0 or i [0] == 2 :
65
s1 = Surface (z = z, opt_3d = "none", mask = "sort", shade = 1)
67
# The purpose of the try clause is to prevent creation of a new Graph
68
# object if g1 already exists. Creation of a new one forces the
69
# current Plotter(s) to close and new one(s) to open. When working
70
# with Xwindows, this leads to annoying popping of windows in and
75
g1 = Graph3d (s1, ambient = 0.2, diffuse = .2, specular = 1.,
76
color_card = "gray.gp", titles = "backlit surface", y_factor = 2.)
78
g1.new (s1, ambient = 0.2, diffuse = .2, specular = 1.,
79
color_card = "gray.gp", titles = "backlit surface", y_factor = 2.)
83
g1.change (titles = "moving light source")
84
g1.move_light_source ()
87
if len (i) == 0 or i [0] == 3 :
91
xyz = zeros ( (3, nx, ny, nz), Float)
92
xyz [0] = multiply.outer ( span (-1, 1, nx), ones ( (ny, nz), Float))
93
xyz [1] = multiply.outer ( ones (nx, Float),
94
multiply.outer ( span (-1, 1, ny), ones (nz, Float)))
95
xyz [2] = multiply.outer ( ones ( (nx, ny), Float), span (-1, 1, nz))
96
r = sqrt (xyz [0] ** 2 + xyz [1] **2 + xyz [2] **2)
97
theta = arccos (xyz [2] / r)
98
phi = arctan2 (xyz [1] , xyz [0] + logical_not (r))
99
y32 = sin (theta) ** 2 * cos (theta) * cos (2 * phi)
101
m1 = Mesh3d (x = span (-1, 1, nx),
102
y = span (-1, 1, ny),
103
z = span (-1, 1, nz),
105
del r, theta, phi, xyz, y32
107
s1 = sslice (m1, .50, varno = 1) # , opt_3d = "f3") # (inner isosurface)
108
s2 = sslice (m1, 1.0, varno = 1) # , opt_3d = "f3") # (outer isosurface)
110
pxy = Plane (array ([0., 0., 1.], Float ), zeros (3, Float))
111
pyz = Plane (array ([1., 0., 0.], Float ), zeros (3, Float))
113
# pseudo-colored plane slice, then cut it in half and save
114
# only the front half
115
s3 = sslice (m1, pyz, opt_3d = ["wm", "f4"])
116
s3 = sslice (s3, pxy, nslices = 1, opt_3d = ["wm", "f4"])
118
# cut the inner isosurface in half so that we can slice the
119
# top off one of the halves:
120
[s1, s4] = sslice (s1, pxy, nslices = 2) #, opt_3d = "f3")
121
s1 = sslice (s1, - pyz) #, opt_3d = "f3")
123
# do the same with the outer isosurface:
124
[s2, s5] = sslice (s2, pxy, nslices = 2) #, opt_3d = "f3")
125
s2 = sslice (s2, - pyz) #, opt_3d = "f3")
127
# The purpose of the try clause is to prevent creation of a new Graph
128
# object if g1 already exists. Creation of a new one forces the
129
# current Plotter(s) to close and new one(s) to open. When working
130
# with Xwindows, this leads to annoying popping of windows in and
135
g1 = Graph3d ([s3, s1, s4, s2, s5], gnomon = 1, color_card =
136
"rainbowhls", diffuse = .2, specular = 1,
137
mask = "min", split = 1) # opt_3d = ["f4"],
139
g1.new ([s3, s1, s4, s2, s5], gnomon = 1, color_card =
140
"rainbowhls", diffuse = .2, specular = 1,
141
mask = "min", split = 1)
146
g1.change (x_factor = 2., y_factor = 2.)