[python] The coordinates of a point on the coordinate axis rotated by a specified angle around the origin

principle:

The coordinates of a point in the image after rotation around the point. The image rotation coordinate position
is calculated as the coordinates of the point after rotation around the origin at a certain angle.

accomplish

import math

# 顺时针旋转
def cw_rotate(x, y, ang):
    ang = math.radians(ang)     # 将角度转换成弧度
    # 用round()保留5位小数
    new_x = round(x * math.cos(ang) + y * math.sin(ang), 5)
    new_y = round(-x * math.sin(ang) + y * math.cos(ang), 5)
    return new_x, new_y

# 逆时针旋转
def ccw_rotate(x, y, ang):
    ang = math.radians(ang)     # 将角度转换成弧度
    # 用round()保留5位小数
    new_x = round(x * math.cos(ang) - y * math.sin(ang), 5)
    new_y = round(x * math.sin(ang) + y * math.cos(ang), 5)
    return new_x, new_y

Guess you like

Origin blog.csdn.net/iiinoname/article/details/124840539