计算机图形学图形旋转
计算机图形学| 回转 (Computer Graphics | Rotation)
Rotation is a type of transformation that is very often used in computer graphics and image processing. Rotation is a process of rotating an object concerning an angle in a two-dimensional plane.
旋转是计算机图形和图像处理中经常使用的一种转换类型。 旋转是使物体在二维平面中旋转一定角度的过程。
It is a process of changing the angle of the object which can be clockwise or anticlockwise, while we have to specify the angle of rotation and rotation point. A rotation point is also called a pivot point.
这是改变对象角度的过程,可以顺时针或逆时针旋转,同时我们必须指定旋转角度和旋转点。 旋转点也称为枢轴点。
There are two types of rotations according to the direction of the movement of the object. These are:
根据对象运动的方向,有两种旋转类型。 这些是:
Anti-clockwise rotation
逆时针旋转
Clockwise rotation
顺时针旋转
The positive value of the rotation angle rotates an object in an anti-clockwise direction while the negative value of the rotation angle rotates an object in a clockwise direction. When we rotate any object, then every point of that object is rotated by the same angle. For example, a straight line is rotated by the endpoints with the same angle and the line is re-drawn between the new endpoints. Also, the polygon is rotated by shifting every vertex with the help of the same rotational angle. Same for circle also, it can be obtained by center position by the specified angle.
旋转角的正值使物体沿逆时针方向旋转,而旋转角的负值使物体沿顺时针方向旋转。 当我们旋转任何对象时,该对象的每个点都旋转相同的角度。 例如,一条直线由端点以相同的角度旋转,并且在新端点之间重新绘制该线。 同样,通过在相同旋转角度的帮助下移动每个顶点来旋转多边形。 圆也一样,可以通过中心位置指定角度来获得。
Let's now consider a point object O which has to be rotated from one angle to another.
现在考虑必须从一个角度旋转到另一个角度的点对象O。
Initial co-ordinates of the object O = (Xold, Yold)
对象的初始坐标O =(X old ,Y old )
Initial angle of the object O with respect to origin = Φ
物体O相对于原点的初始角度=Φ
Rotation angle = θ
旋转角度=θ
New co-ordinates of the object O after rotation = (Xnew, Ynew)
旋转后对象O的新坐标=(X new ,Y new )
![Rotation](https://i-blog.csdnimg.cn/blog_migrate/021ea483747338bbf4c1e6bc040f21be.png)
In order to rotate an object, we need to rotate each vertex of the figure individually. More clearly let us assume a point P, on rotating a point P(x, y) by an angle A about the origin we get a point P' (x', y'). The calculation of values of x' and y' are as follows,
为了旋转对象,我们需要分别旋转图形的每个顶点。 更清楚地让我们假设一个点P ,将点P(x,y)绕原点旋转角度A ,我们得到一个点P'(x',y') 。 x'和y'的值的计算如下:
We know that,
我们知道,
x = r cosB, y = r sinB
x' = r cos ( A + B)
= r ( cosA cosB – sinA sinB )
= r cosB cosA – r sinB sinA
= x cosA – y sinA
y' = r sin ( A + B )
= r ( sinA cosB + cosA sinB )
= r cosB sinA + r sinB cosA
= x sinA + y cosA
It's representation in matrix form will be as follows,
它以矩阵形式表示如下,
![Rotation](https://i-blog.csdnimg.cn/blog_migrate/707e24878265608223cf00753ec6ef22.png)
Now let's understand this by using an example,
现在让我们通过一个例子来理解这一点,
Problem Statement: Given a triangle with corner coordinates (0, 0), (1, 0) and (1, 1). Rotate the triangle by 90 degrees anticlockwise direction and find out the new coordinates.
问题陈述:给定一个三角形,其角坐标为(0,0),(1、0)和(1,1)。 将三角形逆时针旋转90度,找出新坐标。
Solution:
We always rotate a polygon by rotating each of its vertexes with the same rotation angle.
解:
我们总是通过以相同的旋转角度旋转多边形的每个顶点来旋转多边形。
Given,
鉴于
Old corner coordinates of the triangle = A (0, 0), B (1, 0), C (1, 1)
三角形的旧角坐标= A(0,0),B(1,0),C(1,1)
Rotation angle = θ = 90º
旋转角度=θ=90º
For the Co-ordinate A (0, 0)
对于坐标A(0,0)
Let the new coordinates of corner A after rotation = (Xnew, Ynew).
令旋转后角A的新坐标=(X new ,Y new )。
When we apply the rotation equation, we get-
当我们应用旋转方程式时,我们得到-
Xnew = Xold x cosθ – Yold x sinθ
X 新 = X 旧 xcosθ– Y 旧 xsinθ
= 0 x cos90º – 0 x sin90º
= 0 xcos90º– 0 xsin90º
= 0 + 0
= 0 + 0
= 0
= 0
Ynew = Xold x sinθ + Yold x cosθ
Y new = X old xsinθ+ Y old xcosθ
= 0 x sin90º + 0 x cos90º
= 0 xsin90º+ 0 xcos90º
= 0 + 0
= 0 + 0
= 0
= 0
Thus, the new co-ordinates of corner A we get after rotation is = (0, 0).
因此,旋转后我们得到的角A的新坐标为=(0,0)。
For the Coordinate B (1, 0)
对于坐标B(1、0)
Let the new coordinates of corner B after rotation = (Xnew, Ynew).
令旋转后角B的新坐标=(X new ,Y new )。
Xnew = Xold x cosθ – Yold x sinθ
X 新 = X 旧 xcosθ– Y 旧 xsinθ
= 1 x cos90º – 0 x sin90º
= 1 xcos90º– 0 xsin90º
= 0 – 0
= 0 – 0
= 0
= 0
Ynew = Xold x sinθ + Yold x cosθ
Y new = X old xsinθ+ Y old xcosθ
= 1 x sin90º + 0 x cos90º
= 1 xsin90º+ 0 xcos90º
= 1 + 0
= 1 + 0
= 1
= 1
Thus, the new co-ordinates of corner B that we get after rotation are = (0, 1).
因此,旋转后得到的角B的新坐标为=(0,1)。
For the Coordinate C (1, 1)
对于坐标C(1,1)
Let the new coordinates of corner C after rotation = (Xnew, Ynew).
令旋转后角C的新坐标=(X new ,Y new )。
Xnew = Xold x cosθ – Yold x sinθ
X 新 = X 旧 xcosθ– Y 旧 xsinθ
= 1 x cos90º – 1 x sin90º
= 1 xcos90º– 1 xsin90º
= 0 – 1
= 0 – 1
= -1
= -1
Ynew = Xold x sinθ + Yold x cosθ
Y new = X old xsinθ+ Y old xcosθ
= 1 x sin90º + 1 x cos90º
= 1 xsin90º+ 1 xcos90º
= 1 + 0
= 1 + 0
= 1
= 1
Thus, the new co-ordinates of corner C we get after rotation is = (-1, 1).
因此,旋转后得到的角C的新坐标为=(-1,1)。
Thus, the new co-ordinates of the triangle after rotation are = A (0, 0), B (0, 1), C (-1, 1).
因此,旋转后三角形的新坐标为= A(0,0),B(0,1),C(-1,1)。
翻译自: https://www.includehelp.com/computer-graphics/rotation.aspx
计算机图形学图形旋转