From: David S. <dsc...@cm...> - 2000-09-09 18:48:32
|
> 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? It would be nice to have a "surface" primitive in Visual, but I think your basic approach is the best way to approximate one given what's in there now. I would suggest moving the arrows completely above the surface: arrow(pos=(i,j,z+0.2), axis=gradf((i,j,z)), ... As for singularities: One approach is to change the gradf() function to return the zero vector at the origin. A terse way of writing this is: def gradf(v): return vector(v) and norm(v) Alternatively, you could allow norm(v) to raise an exception, and catch it: def gradf(v): try: return norm(v) except ZeroDivisionError: return vector(0,0,0) > 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?). The .label attribute does nothing for most primitives and will eventually vanish. If you have a very recent build of visual, you can use the new (experimental) label primitive. For example: xhat = vector(1,0,0) xaxis=arrow(pos=origin,axis=xhat*10,shaftwidth=vsize,color=color.red) label( pos = xaxis.pos + xhat*8, text = 'X' ) > Finally, I can't seem to define "up" for the screen or view or camera > objects. What is the format? The direction the camera points is controlled by the "forward" attribute, not by "up". Up only controls the camera's rotation around that axis. Try this: scene.forward = (-1,-1,-1) scene.up = (0,0,1) Dave |