python绕点旋转

import numpy as np
import math
import matplotlib.pyplot as plt
# 绕pointx,pointy逆时针旋转
def Nrotate(angle,valuex,valuey,pointx,pointy):
valuex = np.array(valuex)
valuey = np.array(valuey)
nRotatex = (valuex-pointx)*math.cos(angle) - (valuey-pointy)*math.sin(angle) + pointx
nRotatey = (valuex-pointx)*math.sin(angle) + (valuey-pointy)*math.cos(angle) + pointy
return nRotatex, nRotatey
# 绕pointx,pointy顺时针旋转
def Srotate(angle,valuex,valuey,pointx,pointy):
valuex = np.array(valuex)
valuey = np.array(valuey)
sRotatex = (valuex-pointx)*math.cos(angle) + (valuey-pointy)*math.sin(angle) + pointx
sRotatey = (valuey-pointy)*math.cos(angle) - (valuex-pointx)*math.sin(angle) + pointy
return sRotatex,sRotatey

## 绕点坐标
pointx = 7.352847966
pointy = 210

## 旋转前坐标
targetX=6.074863636
targetY=40

## 旋转后坐标   0.5代表°， 注意如果x和y差距较大，则角度相应较小些。
print(sPointx,sPointy)
plt.plot([pointx,targetX],[pointy,targetY])
plt.plot([pointx,sPointx],[pointy,sPointy])
# plt.xlim(-3.,3.)
# plt.ylim(-3.,3.)
# plt.xticks(np.arange(-3.,3.,1))
# plt.yticks(np.arange(-3.,3.,1))
plt.show()
令狐冲
Engineer of offshore wind turbine technique research

My research interests include distributed energy, wind turbine power generation technique , Computational fluid dynamic and programmable matter.