def rotate(self, theta, point=None, axis=None):
"""Rotates the point theta radians around the axis defined by the given
point and axis."""
if not isinstance(theta, Number):
raise TypeError("theta must be scalar.")
if point is None:
center = np.zeros(self.dim)
elif isinstance(point, Point):
center = point._x
else:
raise TypeError("center of rotation must be Point.")
if axis is not None:
raise NotImplementedError("Rotation about axis besides [0 0 1] are"
" not implemented.")
# shift rotation center to origin
self._x -= center
# do rotation
R = np.array([[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]])
self._x = np.dot(R, self._x)
# shift rotation center back
self._x += center
评论列表
文章目录