def rotation_matrix(axis, angle):
"""
Calculate a three dimensional rotation matrix for a rotation around
the given angle and axis.
@type axis: (3,) numpy array
@param angle: angle in radians
@type angle: float
@rtype: (3,3) numpy.array
"""
axis = numpy.asfarray(axis) / norm(axis)
assert axis.shape == (3,)
c = math.cos(angle)
s = math.sin(angle)
r = (1.0 - c) * numpy.outer(axis, axis)
r.flat[[0,4,8]] += c
r.flat[[5,6,1]] += s * axis
r.flat[[7,2,3]] -= s * axis
return r
评论列表
文章目录