⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 图形变换.c

📁 C 语言算法
💻 C
字号:
#include<graphics.h>   
#include<math.h>
 main()   
  {   
  int driver,mode,num;
  float Tx,Ty,x2,y2,x3,y3,x4,y4;
  float j,k,r,i;
  float x0=200,y0=250,x1=300,y1=150; 
  driver=DETECT;   
  mode=0;   
  initgraph(&driver,&mode,"c:\\tc\\bgi");
  setlinestyle(0,0,1);
  /*画坐标系*/
  setcolor(YELLOW); /*坐标系颜色为黄色*/   
  line(20,250,500,250);
  line(200,450,200,50);
  line(490,260,500,250);
  line(490,240,500,250); 
  line(190,60,200,50); 
  line(210,60,200,50);
  
  /*画初始直线*/  
  setcolor(WHITE);  
  line(x0,y0,x1,y1);
  printf("Please input the number as below:\n1-Translation  2-scaling  3-Mirror\n");
  printf("4-CuoQie  5-Rotation%4c\n");
 /*几何变换*/
  scanf("%d",&num);
   switch(num)
   { 
    case 1: /*平移变换-Translation*/
    
    printf("Please input the Tx,Ty:\n",Tx,Ty); /*Tx、Ty表示平移量*/
    scanf("%f%f",&Tx,&Ty);
    printf("This is the translation!\n");
    setcolor(LIGHTGREEN);
    line(x0+Tx,y0-Ty,x1+Tx,y1-Ty);
    break; 
   
    case 2: /*比例变换-scaling*/
   
    printf("Please input the Tx,Ty:\n",Tx,Ty); /*Tx、Ty表示比例变量*/
    scanf("%f%f",&Tx,&Ty);
    if(Tx>=0&&Ty>=0) 
    {x2=x0*Tx;
    y2=y0*Ty; 
    x3=x1*Tx;
    y3=y1*Ty;
    printf("This is the scaling!\n");
    setcolor(LIGHTRED);
    line(x2,y2,x3,y3);
    }
    else printf("Tx,Ty can'nt be minus");
    break; 


    case 3: /*对称变换-Mirror*/
    x2=x1;
    y2=y1+200;
    x3=x1-200;
    y3=y1+200;
    x4=x1-200;
    y4=y1;
    setcolor(LIGHTRED);
    line(x0,y0,x2,y2); 
    setcolor(LIGHTMAGENTA);
    line(x0,y0,x3,y3);  
    setcolor(LIGHTBLUE);
    line(x0,y0,x4,y4);   
    printf("LIGHTRED-X  LIGHTMAGENTA-YuanDian  LIGHTBLUE-Y");
    break; 
  
    case 4: /*错切变换-CuoQie*/
    printf("Please input the Tx,Ty:\n",Tx,Ty); /*Tx、Ty表示错切位移量*/
    scanf("%f%f",&Tx,&Ty);
    x2=x0+Tx;
    y2=Ty+y0;
    x3=x1-Tx;
    y3=y1-Ty;
    setcolor(RED);
    line(x2,y2,x3,y3);
    printf("This is the CuoQie !");
    break; 
   
    
    case 5:    /*Rotation-旋转变换*/
 
    printf("Please input the radian:\n",i); 
    scanf("%f",&i);
    j=0.785;
    k=i-j;
    r=(250-y1)/sin(j);
    setcolor(LIGHTBLUE);  
    line(x0,y0,x2=r*cos(k)+200,y2=r*sin(k)+250);
    printf("This is the Rotation !");
    break; 
    
  }  
  getch();   
  closegraph();  
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -