首页 > 代码库 > 图形的缩放
图形的缩放
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 }
图形的缩放
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。