How to rotate the 2D vector by degree in Python:

46

from math import cos, sin

import numpy as np

theta = np.deg2rad(30)

rot = np.array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]])

v = np.array([1, 0])
w = np.array([3, 4])

v2 = np.dot(rot, v)
w2 = np.dot(rot, w)

print(v2)  # [0.8660254 0.5      ]
print(w2)  # [0.59807621 4.96410162]

Comments

Submit
0 Comments