Search code examples
pythonvectorrotation

Rotation of 3D vector?


I have two vectors as Python lists and an angle. E.g.:

v = [3, 5, 0]
axis = [4, 4, 1]
theta = 1.2  # In radians.

What is the best/easiest way to get the resulting vector when rotating the v vector around the axis?

The rotation should appear to be counter clockwise for an observer to whom the axis vector is pointing. This is called the right hand rule


Solution

  • Take a look at http://vpython.org/contents/docs/visual/VisualIntro.html.

    It provides a vector class which has a method A.rotate(theta,B). It also provides a helper function rotate(A,theta,B) if you don't want to call the method on A.

    http://vpython.org/contents/docs/visual/vector.html