码迷,mamicode.com
首页 > 其他好文 > 详细

图形的旋转

时间:2017-05-18 16:46:01      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:please   draw   角度   poi   需要   存储   str   code   实现   

1.编码实现绕原点的旋转变换(旋转角度由键盘输入),

2.绕任意一点的旋转变换(由键盘输入旋转角度和旋转中心)

编译器:vs2013 

 1 #include "stdafx.h"
 2 #include<stdio.h>
 3 #include"graphics.h"
 4 #include<stdlib.h>
 5 #include<math.h>
 6 
 7 #define PI 3.14159
 8 
 9 void spin00(int a[], double angle);
10 void spinxy(int a[], double angle, int x, int y);
11 
12 int main()
13 {
14     int gdriver=DETECT, gmove;
15     double angle;
16     int a[28] = { 100, 100, 150, 150, 250, 150, 250, 0, 350, 150, 450, 150, 500, 200, 450, 250, 350, 250, 250, 400, 250, 250, 150, 250, 100, 300, 100, 100 };
17 
18     /*printf("please input the angle:\n");
19     scanf_s("%lf", &angle);
20 
21     initgraph(&gdriver, &gmove, "");
22 
23     drawpoly(14, a);
24 
25     spin00(a, angle);*/
26 
27     int x, y;
28 
29     printf("please input the angle:\n");
30     scanf_s("%lf", &angle);
31     printf("please input the point:\n");
32     scanf_s("%d%d", &x, &y);
33 
34     initgraph(&gdriver, &gmove, "");
35 
36     spinxy(a, angle, x, y);
37 
38     system("pause");
39 
40     closegraph();
41 
42     return 0;
43 }
44 
45 //绕原点旋转变换
46 void spin00(int a[], double angle)
47 {
48     int i,b[28];
49 
50     for (i = 0; i < 28; i = i + 2)
51     {
52         b[i] = a[i] * cos(angle / 180.0*PI) - a[i + 1] * sin(angle / 180.0*PI);
53         b[i + 1] = a[i] * sin(angle / 180.0*PI) + a[i + 1] * cos(angle / 180.0*PI);
54     }
55 
56     drawpoly(14, b);
57 }
58 
59 //绕(x,y)旋转变换
60 void spinxy(int a[], double angle, int x, int y)
61 {
62     int i, b[28],t;
63 
64     for (i = 0; i < 28; i = i + 2)
65     {
66         b[i] = a[i] - x;
67         b[i + 1] = a[i + 1] - y;
68         t = b[i];
69         b[i] = b[i] * cos(angle / 180.0*PI) - b[i + 1] * sin(angle / 180.0*PI);
70         b[i + 1] = t * sin(angle / 180.0*PI) + b[i + 1] * cos(angle / 180.0*PI);
71         b[i] = b[i] + x;
72         b[i + 1] = b[i + 1] + y;
73     }
74 
75     drawpoly(14, b);
76 }

 

结:在第二题时需要注意b[i]在操作过程中被改变,需要设置新变量来存储旧值

图形的旋转

标签:please   draw   角度   poi   需要   存储   str   code   实现   

原文地址:http://www.cnblogs.com/cdp1591652208/p/6873776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!