简体   繁体   English

如何从中心找到旋转矩形的顶点?

[英]How do you find the verticies of a rotated rectangle from its center?

I have a rectangle that I've rotated around its center by an angle. 我有一个矩形,我围绕它的中心旋转了一个角度。 How can I derive the verticies from the rectangle? 如何从矩形派生顶点?

Apply the rotation matrix to the vertices. 旋转矩阵应用于顶点。

For example, if the the origin is in the center of your rectangle and the coordinates of a vertex are given by vx and vy Then the new coordinates for this vertex are given by: 例如,如果原点位于矩形的中心,并且顶点的坐标由vx和vy给出,则此顶点的新坐标由下式给出:

v_new.x=v.x*cos(angle)-v.y*sin(angle)
v_new.y=v.x*sin(angle)+v.y*cos(angle)

(assuming counter clockwise rotation ) (假设逆时针旋转

Translate such that the rectangle's center is (0,0). 翻译使矩形的中心为(0,0)。 View each point as not part of the rectangle, but as part of a circle, and the line segment from the rectangle's center as the center of that circle. 将每个点视为不是矩形的一部分,而是作为圆的一部分,并将矩形中心的线段视为该圆的中心。 Then you are solving a different problem: given a circle at the origin and a point on that circle (or line segment), what is the point (angle) degrees rotated around the circle. 然后你解决了一个不同的问题:在原点处给定一个圆,在该圆(或线段)上给出一个点,围绕圆旋转的点(角度)是多少。 I'll leave looking up the appropriate algorithm for that one to you :) 我会留给你找那个合适的算法:)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM