参考https://blog.youkuaiyun.com/x1131230123/article/details/127555266
cv默认坐标系y轴朝下
python:
import math
import numpy as np
import cv2
# -------- 创建画布 --------
# 指定画布的大小
canvas_size = [700, 400, 3]
# 指定画布颜色
canvas_color = 255, 255, 255
canvas = np.ones(canvas_size, dtype=np.uint8)
canvas[:] = canvas_color
# --------------------------------------
angle = math.radians(90)
p1x, p1y = 100, 100 #要旋转的矩形坐标
p2x, p2y = 200, 100
p3x, p3y = 100, 200
p4x, p4y = 200, 200
px, py = 100, 200 #旋转中心点
p1x = int(px + (p1x - px) * math.cos(angle) - (py - p1y) * math.sin(angle)) #坐标点旋转
p1y = int(py - (p1x - px) * math.sin(angle) - (py - p1y) * math.cos(angle))
p2x = int(px + (p2x - px) * math.cos(angle) - (py - p2y) * math.sin(angle))
p2y = int(py - (p2x - px) * math.sin(angle) - (py - p2y) * math.cos(angle))
p3x = int(px + (p3x - px) * math.cos(angle) - (py - p3y) * math.sin(angle))
p3y = int(py - (p3x - px) * math.sin(angle) - (py - p3y) * math.cos(angle))
p4x = int(px + (p4x - px) * math.cos(angle) - (py - p4y) * math.sin(angle))
p4y = int(py - (p4x - px) * math.sin(angle) - (py - p4y) * math.cos(angle))
p1 = (p1x, p1y)
p2 = (p2x, p2y)
p3 = (p3x, p3y)
p4 = (p4x, p4y)
cv2.line(canvas, p1, p2, (0, 0, 255), 1)
cv2.line(canvas, p3, p4, (0, 0, 255), 1)
cv2.line(canvas, p1, p3, (0, 0, 255), 1)
cv2.line(canvas, p2, p4, (0, 0, 255), 1)
cv2.imshow("canvas",canvas)
cv2.waitKey(0)