如下所示:
(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实现一个点绕另一个点旋转后的坐标就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
标签:
python,旋转,坐标
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“python实现一个点绕另一个点旋转后的坐标”评论...
更新动态
2024年11月29日
2024年11月29日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]