import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
print(mpl.get_backend())
def rotate(xy,deg,rp):
"""xy is the path, deg is degrees of rotation, rp is the rotation point"""
#translate first, rotate, then retranslate
xy = xy-rp
i=0
while i<len(xy):
xy[i][0]= xy[i][0]*np.cos(np.deg2rad(deg))-(xy[i][1]*np.sin(np.deg2rad(deg)))
xy[i][1]= xy[i][0]*np.sin(np.deg2rad(deg))+xy[i][1]*np.cos(np.deg2rad(deg))
i+=1
return xy+rp
#fig = plt.figure()
#ax = fig.add_subplot(111)
f,(ax) = plt.subplots(1,1,figsize=(8,8))
f.subplots_adjust(hspace=0,wspace=0)
ax.set_xlim(0,10)
ax.set_ylim(-2,8)
plt.grid(True)
plt.xticks(np.arange(0, 10+1, 0.5))
plt.yticks(np.arange(-2, 8+1, 0.5))
def xy(height=1.3,width=2,center=(0,0)):
num = []
ran1 = range(0,361)
b=height#height
a=width#width
i=360
femur_dict = {}
xcen=center[0]
ycen=center[1]
for counter in range(0,360):
num.append(np.array([a*np.cos(np.deg2rad(counter))+xcen,b*np.sin(np.deg2rad(ran1[counter]))+ycen]))
i-=1
return num
scale = 1
t2 = mpl.patches.Polygon(xy(center=(7,7),height=1*scale,width=0.25*scale),fc="blue")
td2dis = ax.transData
coords = td2dis.transform(t2.get_xy()[270])
#rotate transform
tr = mpl.transforms.Affine2D().rotate_deg_around(coords[0], coords[1], -90)
t = td2dis + tr
t3=mpl.patches.Polygon(t2.get_xy(),fc='green',alpha=0.5,zorder=10000)
t3.set_transform(t)
t4 = mpl.patches.Polygon(rotate(xy(center=(7,7),height=1*scale,width=0.25*scale),45,t2.get_xy()[270]),fc="red")
ax.add_patch(t4)
ax.add_patch(t2)
ax.add_patch(t3)
plt.show()
I want to rotate an object manually. I need to access the raw coordinates of an object after applying a transform. How do i access the transformed coordinates of t3?
The red is manual rotation and its not working but the function is coorect. Matplotlib ask too much.