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

图形的缩放

时间:2017-05-18 16:45:38      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:图形   ble   定义   for   bsp   sys   pause   比例   lease   

1.编码实现相对坐标原点的缩放变换(缩放比例由键盘输入)

2.相对任意一点的缩放变换(缩放的参考点由用户确定)

编译器:vs2013

 1 // ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
 2 //
 3 
 4 #include "stdafx.h"
 5 #include<stdio.h>
 6 #include"graphics.h"
 7 #include<stdlib.h>
 8 
 9 void zoom00(int a[],double sx,double sy);
10 void zoomxy(int a[], double sx, double sy,int x, int y);
11 
12 int main()
13 {
14     int gdriver = DETECT, gmove,i,x,y;
15     double sx, sy;
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:\n");
19     scanf_s("%lf%lf", &sx,&sy);
20 
21     initgraph(&gdriver, &gmove, "");
22 
23     drawpoly(14,a);
24 
25     zoom00(a, sx,sy);*/
26 
27     printf("Please input the point:\n");
28     scanf_s("%d%d", &x, &y);
29 
30     printf("Please input:\n");
31     scanf_s("%lf%lf", &sx, &sy);
32 
33     initgraph(&gdriver, &gmove, "");
34 
35     zoomxy(a, sx, sy,x, y);
36 
37     system("pause");
38 
39     closegraph();
40 
41     return 0;
42 }
43 
44 //相对于原点缩放
45 void zoom00(int a[],double sx,double sy)
46 {
47     int b[3][3] = { { sx, 0, 0 }, { 0, sy, 0 }, { 0, 0, 1 } }, c[28], i, j;
48 
49     for (i = 0; i < 28; i = i + 2)
50     {
51         c[i] = a[i] * sx;
52         c[i + 1] = a[i + 1] * sy;
53     }
54 
55     drawpoly(14, c);
56 }
57 
58 //相对于任意一点缩放
59 void zoomxy(int a[], double sx, double sy,int x,int y)
60 {
61     int b[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { x,y ,1 } }, c[28], i, j;
62 
63     for (i = 0; i < 28; i = i + 2)
64     {
65         c[i] = a[i] - x;
66         c[i + 1] = a[i + 1] - y;
67         c[i] *= sx;
68         c[i + 1] *= sy;
69         c[i] += x;
70         c[i+1] += y;
71     }
72 
73     drawpoly(14, c);
74 }

 

图形的缩放

标签:图形   ble   定义   for   bsp   sys   pause   比例   lease   

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

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