Skip to content

Instantly share code, notes, and snippets.

@rise-worlds
Last active October 25, 2023 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rise-worlds/5657a970a66fbf2588193b7b3e6d9387 to your computer and use it in GitHub Desktop.
Save rise-worlds/5657a970a66fbf2588193b7b3e6d9387 to your computer and use it in GitHub Desktop.
code record
# code record
## 以中心点旋转点.py
import math
def rotate_point_around_center(x, y, center_x, center_y, angle):
"""
以中心点旋转点
Args:
x: 点的x坐标
y: 点的y坐标
center_x: 中心点的x坐标
center_y: 中心点的y坐标
angle: 旋转角度,单位为度
Returns:
旋转后的点的坐标
"""
angle = math.radians(angle)
x_prime = (y - center_y) * math.cos(angle) - (x - center_x) * math.sin(angle) + center_x
y_prime = (x - center_x) * math.cos(angle) + (y - center_y) * math.sin(angle) + center_y
# 交换x和y坐标
x_prime, y_prime = y_prime, x_prime
return x_prime, y_prime
x = 690
y = 350
image_width = 720
image_height = 1280
center_x = image_width / 2
center_y = image_height / 2
angle = 90
x_prime, y_prime = rotate_point_around_center(x, y, center_x, center_y, angle)
print(x_prime, y_prime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment