输入坐标轴,X轴,Y轴,判断该坐标在第几象限。然后根据象限以原点为中心。进行坐标的旋转。
import math
import numpy as np
# 逆时针旋转
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 round(nRotatex, 2), round(nRotatey, 2)
# 顺时针旋转
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
# 判断,坐标轴在第几象限
if pointx > 0:
if pointy > 0:
xx = 1
elif pointy < 0:
xx = 4
elif pointx < 0:
if pointy > 0:
xx = 2
else:
xx = 3
# 第一象限保持不变
if xx == 1:
# 参数(角度,要旋转的点,要绕的点)
sPointx, sPointy = Srotate(math.radians(0), pointx, pointy, 0, 0)
print(round(sPointx, 2), round(sPointy, 2))
# 第二象限顺时针旋转90度
if xx == 2:
sPointx, sPointy = Srotate(math.radians(90), pointx, pointy, 0, 0)
print(round(sPointx, 2), round(sPointy, 2))
# 第三象限顺时针旋转 180度
if xx == 3:
sPointx, sPointy = Srotate(math.radians(180), pointx, pointy, 0, 0)
print(round(sPointx, 2), round(sPointy, 2))
# 第四象限,逆时针旋转90度
if xx == 4:
sPointx, sPointy = Nrotate(math.radians(180), pointx, pointy, 0, 0)
print(round(sPointx, 2), round(sPointy, 2))



