Standard rotation of a 2D vector with a rotation matrix (see https://en.wikipedia.org/wiki/Rotation_matrix ) >>> rotate(np.array([1, 0]), 60) array([0.5 , 0.8660254]) >>> rotate(np.array([1, 0]), 90) array([6.123234e-17, 1.000000e+00])
(vector: np.ndarray, angle_in_degrees: float)
| 75 | |
| 76 | |
| 77 | def rotate(vector: np.ndarray, angle_in_degrees: float) -> np.ndarray: |
| 78 | """ |
| 79 | Standard rotation of a 2D vector with a rotation matrix |
| 80 | (see https://en.wikipedia.org/wiki/Rotation_matrix ) |
| 81 | >>> rotate(np.array([1, 0]), 60) |
| 82 | array([0.5 , 0.8660254]) |
| 83 | >>> rotate(np.array([1, 0]), 90) |
| 84 | array([6.123234e-17, 1.000000e+00]) |
| 85 | """ |
| 86 | theta = np.radians(angle_in_degrees) |
| 87 | c, s = np.cos(theta), np.sin(theta) |
| 88 | rotation_matrix = np.array(((c, -s), (s, c))) |
| 89 | return np.dot(rotation_matrix, vector) |
| 90 | |
| 91 | |
| 92 | def plot(vectors: list[np.ndarray]) -> None: |