大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章将为大家详细讲解有关python如何实现一个点绕另一个点旋转后的坐标,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
成都创新互联公司始终坚持【策划先行,效果至上】的经营理念,通过多达十年累计超上千家客户的网站建设总结了一套系统有效的营销解决方案,现已广泛运用于各行各业的客户,其中包括:酒店设计等企业,备受客户赞扬。如下所示:
(x,y)为要转的点,(pointx,pointy)为中心点,如果顺时针角度为angle
srx = (x-pointx)*cos(angle) + (y-pointy)*sin(angle)+pointx
sry = (y-pointy)*cos(angle) - (x-pointx)*sin(angle)+pointy
(x,y)为要转的点,(pointx,pointy)为中心点,如果逆时针角度为angle
nrx = (x-pointx)*cos(angle) - (y-pointy)*sin(angle)+pointx
nry = (x-pointx)*sin(angle) + (y-pointy)*cos(angle)+pointy
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 = 1 pointy = 1 sPointx ,sPointy = Nrotate(math.radians(45),pointx,pointy,0,0) print(sPointx,sPointy) plt.plot([0,pointx],[0,pointy]) plt.plot([0,sPointx],[0,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()
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 x1 = np.array([1,2,3]) y1 = np.array([1,2,3]) x2 = np.array([3,6]) y2 = np.array([2,1]) # x2往x1上拼 disx = x2[0]-x1[0] disy = y2[0]-y1[0] removeX2 = x2-disx removeY2 = y2-disy tany1 = y1[-1]-y1[0] tanx1 = x1[-1]-x1[0] angle1 = math.degrees(np.arctan(tany1/tanx1)) tany2 = y2[-1]-y2[0] tanx2 = x2[-1]-x2[0] angle2 = math.degrees(np.arctan(tany2/tanx2)) disAngle = angle2-angle1 print(angle1) print(angle2) print(disAngle) if disAngle<0: rotateX,rotateY = Nrotate(math.radians(abs(disAngle)),removeX2,removeY2,x1[0],y1[0]) else: rotateX,rotateY = Srotate(math.radians(abs(disAngle)),removeX2,removeY2,x1[0],y1[0]) plt.plot(x1,y1,color='red') plt.plot(removeX2,removeY2,color='green') plt.scatter(rotateX,rotateY,color='yellow') plt.xlim(0.,10.) plt.ylim(0.,10.) plt.xticks(np.arange(0.,10.,1)) plt.yticks(np.arange(0.,10.,1)) plt.show()
关于“python如何实现一个点绕另一个点旋转后的坐标”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。