Reputation: 2621
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 degrees (take one of the two points as a origin) how should I do?
Upvotes: 1
Views: 8170
Reputation: 494
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()
Upvotes: 1
Reputation: 11691
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
Upvotes: 3