Python: How To Rotate A Line 45 Degrees
I have two points and plot them as a line as below picture. fig=plt.figure(figsize=(7,6)) plt.plot(lont[-2:],latt[-2:],'b') plt.show() and now I want to rotated this line 45 degr
Solution 1:
A rotation looks like the following:
newx = (x1 - xorigin)*cos(45 * pi / 180)
newy = (y1 - yorigin)*sin(45 * pi / 180)
If one of your points is the origin you only need apply it to the other point
Solution 2:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
angle = np.deg2rad(45)
lont = pd.Series([1, 2, 4, 6])
latt = pd.Series([4, 6, 3, 2])
R = (lont.diff()**2 + latt.diff()**2)**0.5
theta = np.arctan(latt.diff()/lont.diff())
Xnew = lont.shift(1)+ R*np.cos(angle + theta)
Ynew = latt.shift(1) + R*np.sin(angle+ theta)
fig=plt.figure()
plt.plot(lont, latt,'-ob')
plt.plot([lont.iloc[-n-2], Xnew.iloc[-n-1]], [latt.iloc[-n-2], Ynew.iloc[-n-1]], ":*r")
plt.show()
Post a Comment for "Python: How To Rotate A Line 45 Degrees"