From: Bruce S. <bas...@nc...> - 2010-09-15 18:59:29
|
Here's another successful test. I replaced the import statements at the start of the example program gas.py with the following import statements, and deleted the old Numeric code in a try structure: from visual.cvisual import (vector, mag, mag2, norm, dot, cross, rotate, comp, proj, diff_angle, rate, waitclose) from visual.primitives import (arrow, cylinder, cone, sphere, box, ring, label, frame, pyramid, ellipsoid, curve, faces, convex, helix, points, text, distant_light, local_light) from visual.ui import display import visual.crayola as color import visual.materials as materials import visual.site_settings import atexit as _atexit _atexit.register(waitclose) from math import pi, sin, cos, exp from numpy import (sqrt, array, newaxis, add, less_equal, identity, sort, nonzero, greater_equal, arange) from visual.graph import (gdisplay, gcurve, ghistogram) from random import random This could have been more selective, since gas.py uses only a few of the vector and primitive features. Also, gas.py already has a scene = display(....) statement. A subtle point that one should be aware of: In visual's __init__.py there is some complex machinery to deal with the fact that when, for example, you're taking the square root of a scalar you want to use the math module's sqrt, because it is much faster than using numpy's sqrt. On the other hand, you need to use numpy's sqrt if you're taking the square roots of all the elements of a numpy array. For functions such as sqrt you would want to do something like this: from math import sqrt as msqrt from numpy import sqrt as nsqrt Then you would use msqrt or nsqrt depending on the argument. The machinery in __init__.py takes care of this for you and applies the faster sqrt when the argument is a scalar. Bruce Sherwood |