MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / rotate

Function rotate

fractals/koch_snowflake.py:77–89  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

75
76
77def 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
92def plot(vectors: list[np.ndarray]) -> None:

Callers 1

iteration_stepFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected