• 图形的缩放


    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:
    ");
    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:
    ");
    28     scanf_s("%d%d", &x, &y);
    29 
    30     printf("Please input:
    ");
    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 }
  • 相关阅读:
    NET性能优化方面的总结
    SVN 全局忽略列表
    Visual Studio 2005 IDE Themes
    如何编写网络监视器
    微软研究院Detour开发包之API拦截技术
    NDIS HOOK实现方法
    如何使用MAP文件找到程序崩溃时源码是哪行异常
    QT 环境变量设置
    Winsock工作模型 ( 转 )
    如何使用MAP文件找到程序崩溃的原因
  • 原文地址:https://www.cnblogs.com/cdp1591652208/p/6873796.html
Copyright © 2020-2023  润新知