简体   繁体   English

如何计算具有 4 个点 (x1,y1,.,x4,y4) 的矩形在顺时针方向上的旋转角度,使其笔直或 0 度

[英]How to calculate rotation angle of a rectangle with 4 points (x1,y1,.,x4,y4) in clock-wise direction, to make it straight or 0 degree

给定一个多边形(倾斜矩形),它代表一个单词区域,其中 4 个点按顺时针方向排列,如何识别旋转角度以使其在视角中为 0 度以使文本歪斜?

I guess the rectangle looks like this?!我猜矩形看起来像这样?!

在此处输入图像描述

The red angle, let's call it alpha , is your rotation angle.红色角度,我们称之为alpha ,是您的旋转角度。 Let's say the top left point is named A and top right is called B .假设左上角名为A ,右上角名为B The line from A to B is the hypotenuse of the red triangle which is as long as the width of the rectangle.AB的线是红色三角形的斜边,与矩形的宽度一样长。 The opposite cathetus is the right side of the red triangle which is as long as the difference between the y coordinates of A and B .对面的导管是红色三角形的右侧,与ABy坐标之间的差一样长。

The sine function is defined as the opposite cathetus divided by the hyptenuse.正弦函数被定义为对面导管除以斜边。

sin(alpha) = (y_A-y_B)/width -> alpha = sin^-1((y_A-y_B)/width) sin(alpha) = (y_A-y_B)/width -> alpha = sin^-1((y_A-y_B)/width)

# I guess the coordinates are stored in a list (x1,y1,...,x4,y4) called coords
y_A = coords[1]
y_B = coords[3]

op_cath = y_A - y_B

import math
alpha = math.asin(op_cath/width)

To get the new coordinates (rotation).获取新坐标(旋转)。

# new coordinates of A
x_A = x_A*math.cos(alpha)-y_A*math.sin(alpha)
y_A = x_A*math.sin(alpha)+y_A*math.cos(alpha)

# repeat for each point

( https://math.stackexchange.com/questions/2581058/rotating-rectangle-by-its-center ) https://math.stackexchange.com/questions/2581058/rotating-rectangle-by-its-center

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何计算x,y坐标的点相对于直线的比例百分比(也有x1,y1,x2,y2) - How to calculate the proportional percentage of a point of an x,y coordinate with respect to a line (also with x1, y1, x2, y2) 如何将 numpy 数组 [(x1,y1),(x2,y2),(x3,y3),...(xn,yn)] 转换为 [(x1,y1,x1^2,y1^2),(x2 ,y2,x2^2,y2^2),…(xn,yn,xn^2,yn^2)] - How to convert a numpy array [(x1,y1),(x2,y2),(x3,y3),…(xn,yn)] to [(x1,y1,x1^2,y1^2),(x2,y2,x2^2,y2^2),…(xn,yn,xn^2,yn^2)] 查找距离 X1 和 Y1 - Find distance X1 and Y1 在同一 plot 中绘制多条曲线 (x, y1, y2, x, y3, y4) - Ploting multiple curves (x, y1, y2, x, y3, y4) in the same plot x, y 方向到度 - x, y direction to degree 坐标几何/如何用点(x1 y1)和(x2 y2)之间的距离分配point_dist? - Coordinates geometry / How to assign point_dist with distance between points (x1 y1) and (x2 y2)? 使用matplotlib.pyplot [[x1,y1],[x2,y2]]绘制点 - draw points using matplotlib.pyplot [[x1,y1],[x2,y2]] 如何从列表中表达 x1, y1, x2, y2 - How to express x1, y1, x2, y2 from a list Python中如何将YOLO格式标注转换为x1,y1,x2,y2坐标? - How to convert YOLO format annotations to x1, y1, x2, y2 coordinates in Python? 如何通过在pyglet窗口中拖动鼠标将.png从x,y拖动到x1,y1 - How to drag .png from x,y to x1,y1 by draging with mouse in pyglet window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM