Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 #radian 

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

like image 465
Mads Skjern Avatar asked Jul 23 '11 18:07

Mads Skjern


People also ask

How do you find the rotation of a vector?

The formula for finding the rotation matrix corresponding to an angle-axis vector is called Rodrigues' formula, which is now derived. Let r be a rotation vector. If the vector is (0,0,0), then the rotation is zero, and the corresponding matrix is the identity matrix: r = 0 → R = I . such that p = r.


1 Answers

Using the Euler-Rodrigues formula:

import numpy as np import math  def rotation_matrix(axis, theta):     """     Return the rotation matrix associated with counterclockwise rotation about     the given axis by theta radians.     """     axis = np.asarray(axis)     axis = axis / math.sqrt(np.dot(axis, axis))     a = math.cos(theta / 2.0)     b, c, d = -axis * math.sin(theta / 2.0)     aa, bb, cc, dd = a * a, b * b, c * c, d * d     bc, ad, ac, ab, bd, cd = b * c, a * d, a * c, a * b, b * d, c * d     return np.array([[aa + bb - cc - dd, 2 * (bc + ad), 2 * (bd - ac)],                      [2 * (bc - ad), aa + cc - bb - dd, 2 * (cd + ab)],                      [2 * (bd + ac), 2 * (cd - ab), aa + dd - bb - cc]])  v = [3, 5, 0] axis = [4, 4, 1] theta = 1.2   print(np.dot(rotation_matrix(axis, theta), v))  # [ 2.74911638  4.77180932  1.91629719] 
like image 182
unutbu Avatar answered Oct 03 '22 19:10

unutbu