Wednesday, 5 January 2011

Debugging vectors in 3D

Ever need to figure out the relationship between various 3D vectors? One way to do this is to draw the vectors using VPython.

When you run the following code using VPython's VIdle on Windows, an interactive window pops up where you can rotate the scene by holding down the right mouse button:
from visual import *

floor = box(pos=(0,0,0), length=4, width=4,
height=0.01, color=color.blue)
xaxis = arrow(pos=(0,0,0), axis=(1,0,0), color=color.green)
yaxis = arrow(pos=(0,0,0), axis=(0,1,0), color=color.red)
Does anyone know a different way to draw and interact with 3D vectors?

2 comments:

Andrew Dalke said...

You can draw vectors like this in VMD. See http://www.ks.uiuc.edu/Research/vmd/current/ug/node123.html . I have no idea if the Python API supports the "draw" commands.

steino said...

We use vmd to draw vectors, we hacked together a handy little tcl script which draws the vector with the origin on a given atom and draws a label at the end.

It's extra nice since you can easily draw orbitals and stuff in VMD also.