这是更改对象角度的过程。旋转可以是顺时针或逆时针。对于旋转, 我们必须指定旋转角度和旋转点。旋转点也称为枢轴点。打印关于旋转哪个对象的信息。
旋转类型
- 逆时针方向
- 逆时针方向
枢轴点的负值(旋转角度)使对象沿顺时针方向旋转。
旋转对象时, 对象的每个点都旋转相同的角度。
直线:直线由端点以相同角度旋转, 并在新端点之间重画线。
多边形:通过使用相同的旋转角度移动每个顶点来旋转多边形。
曲线:通过重新放置所有点并在新位置绘制曲线来旋转曲线。
圆:可以通过中心位置指定角度获得。
椭圆:可以通过将椭圆的长轴和短轴旋转所需角度??来获得其旋转。

文章图片

文章图片
旋转矩阵为顺时针方向。

文章图片
旋转矩阵是逆时??针方向。

文章图片
均匀坐标旋转矩阵(顺时针)

文章图片
齐次坐标旋转矩阵(逆时针)

文章图片
围绕任意点旋转:如果要旋转对象或围绕任意点旋转点, 首先, 我们将要围绕其旋转的点转换为原点。然后围绕原点旋转点或对象, 最后, 再次将其平移到原始位置。我们绕任意点旋转。
示例:要旋转点(x, y)
(xc yc)是绕逆时针方向旋转的点
步骤1:将点(xc yc)转换为原点

文章图片
步骤2:围绕原点旋转(x, y)

文章图片
步骤3:将旋转中心平移回原始位置

文章图片

文章图片
示例1:证明围绕原点的2D旋转是可交换的, 即R1 R2 = R2 R1。
解决方案:R1和R2是旋转矩阵

文章图片
示例2:绕着原点旋转线CD, 使其端点为(3, 4)和(12, 15), 沿逆时针方向旋转45°。
解决方案:点C(3, 4)

文章图片

文章图片

文章图片
例3:绕线AB绕其原点沿顺时针方向旋转AB, 端点为A(2, 5)和B(6, 12)。
解决方案:沿顺时针方向旋转。矩阵是

文章图片
步骤1:旋转点A(2, 5)。取角30°

文章图片
步骤2:旋转B点(6, 12)

文章图片

文章图片
旋转线的程序:
#include<
stdio.h>
#include<
graphics.h>
#include<
math.h>
int main(){ intgd=0, gm, x1, y1, x2, y2;
double s, c, angle;
initgraph(&
gd, &
gm, "C:\\TC\\BGI");
setcolor(RED);
printf("Enter coordinates of line: ");
scanf("%d%d%d%d", &
x1, &
y1, &
x2, &
y2);
cleardevice();
setbkcolor(WHITE);
line(x1, y1, x2, y2);
getch();
setbkcolor(BLACK);
printf("Enter rotation angle: ");
scanf("%lf", &
angle);
setbkcolor(WHITE);
c = cos(angle *3.14/180);
s = sin(angle *3.14/180);
x1 = floor(x1 * c + y1 * s);
y1 = floor(-x1 * s + y1 * c);
x2 = floor(x2 * c + y2 * s);
y2 = floor(-x2 * s + y2 * c);
cleardevice();
line(x1, y1 , x2, y2);
getch();
closegraph();
return 0;
}
输出:
【计算机图形旋转操作详细步骤】旋转前

文章图片

文章图片

文章图片
旋转后

文章图片
程序旋转三角形:
#include<
stdio.h>
#include<
graphics.h>
#include<
math.h>
main(){ intgd=0, gm, x1, y1, x2, y2, x3, y3;
double s, c, angle;
initgraph(&
gd, &
gm, "C:\\TURBOC3\\BGI");
setcolor(RED);
printf("Enter coordinates of triangle: ");
scanf("%d%d%d%d%d%d", &
x1, &
y1, &
x2, &
y2, &
x3, &
y3);
setbkcolor(WHITE);
cleardevice();
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
getch();
setbkcolor(BLACK);
printf("Enter rotation angle: ");
scanf("%lf", &
angle);
setbkcolor(WHITE);
c = cos(angle *M_PI/180);
s = sin(angle *M_PI/180);
x1 = floor(x1 * c + y1 * s);
y1 = floor(-x1 * s + y1 * c);
x2 = floor(x2 * c + y2 * s);
y2 = floor(-x2 * s + y2 * c);
x3 = floor(x3 * c + y3 * s);
y3 = floor(-x3 * s + y3 * c);
cleardevice();
line(x1, y1 , x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
getch();
closegraph();
return 0;
}
输出:
旋转前

文章图片

文章图片

文章图片
旋转后

文章图片
推荐阅读
- 计算机图形(反射操作)
- 计算机图形(缩放比例)
- 计算机图形翻译
- 计算机图形转型介绍
- 计算机扫描线多边形填充算法
- 计算机图形(洪水填充算法)
- 计算机图形(填充区域基元)
- 计算机图形(中点椭圆算法)
- 计算机图形(三角法)