Thanks for signing me up for this list. I'd just started wondering how to
best find answers without pestering any one person. A users group is a good
way of posting ideas and asking questions with possibility of a fast
response.
To kick off, below is my amateur attempt to create a potential surface and
its gradient (field). I was wondering whether there's a better way of
handling this. This isn't very smooth but it's fast and gives the flavor of
what I want. Would there be a better way to handle exceptions, like the
singularites that can result at the origin?
As a suggestion, when I want to clarify for my students the order of some
vectors (like the unit vectors forming the coordinate basis), I always use
the order RGB (red green blue) since that is the canonical ordering of the
colors. Further ordering uses CMY (cyan magenta yellow) since that's the
common abbreviation for printer inks. This way I don't have to use labels to
slow things down (but the real reason is that I haven't figured those out
yet -- help?).
############################################# f-gradf.py
from visual import *
import floatdivision
origin=(0,0,0)
vsize=0.1
xhat=(1,0,0);
xaxis=arrow(pos=origin,axis=xhat,shaftwidth=vsize,color=color.red,
label='x')
yhat=(0,1,0);
yaxis=arrow(pos=origin,axis=yhat,shaftwidth=vsize,color=color.green)
zhat=(0,0,1);
zaxis=arrow(pos=origin,axis=zhat,shaftwidth=vsize,color=color.blue)
def f(r): #the scalar field
return mag(r)
def gradf(r): #the gradient of the scalar field
return norm(r)
for i in arange(-10,10,1):
for j in arange(-10,10,1):
v=(i,j,0)
z= f(v)
a = convex(color=(1,z/10,0))
v=(i+.5,j+.5,0)
z= f(v)
a.append(pos = (i+.5,j+.5,z))
v=(i-.5,j+.5,0)
z= f(v)
a.append(pos = (i-.5,j+.5,z))
v=(i-.5,j-.5,0)
z= f(v)
a.append(pos = (i-.5,j-.5,z))
v=(i+.5,j-.5,0)
z= f(v)
a.append(pos = (i+.5,j-.5,z))
v=(i+.5,j+.5,0)
z= f(v)
a.append(pos = (i+.5,j+.5,z))
if not (i==0 and j==0):
v=(i,j,0)
z= f(v)
arrow(pos=(i,j,z),axis=gradf((i,j,z)),shaftwidth=vsize,color=color.red)
#############################################
Finally, I can't seem to define "up" for the screen or view or camera
objects. What is the format?
Any responses, critiques, etc. are welcomed.
Larry Martin, Ph.D.
Professor of Physics
North Park University
Dept. of Physics, box 30
3225 West Foster Ave.
Chicago, IL 60625-4895
(773) 244-5668 FAX (773) 279-7952
http://www.admin.northpark.edu/LMartin
LM...@no...
|