Skip to content

Instantly share code, notes, and snippets.

@KrisYu
Last active October 25, 2021 20:00
Show Gist options
  • Save KrisYu/213e32219d52494d5d04880d6424a2aa to your computer and use it in GitHub Desktop.
Save KrisYu/213e32219d52494d5d04880d6424a2aa to your computer and use it in GitHub Desktop.
Rotate point about another point in degrees python
#https://stackoverflow.com/questions/34372480/rotate-point-about-another-point-in-degrees-python
import numpy as np
def rotate(p, origin=(0, 0), degrees=0):
angle = np.deg2rad(degrees)
R = np.array([[np.cos(angle), -np.sin(angle)],
[np.sin(angle), np.cos(angle)]])
# atleast_2d View inputs as arrays with at least two dimensions.
o = np.atleast_2d(origin)
p = np.atleast_2d(p)
return np.squeeze((R @ (p.T-o.T) + o.T).T)
points=[(200, 300), (100, 300)]
origin=(100,100)
new_points = rotate(points, origin=origin, degrees=10)
print(new_points)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment