當前位置:編程學習大全網 - 編程語言 - 高分求c語言課設 圖形旋轉問題

高分求c語言課設 圖形旋轉問題

#include <graphics.h>

#include <conio.h>

#include <math.h>

#include <stdio.h>

#define PI 3.1415926

int s_x1=150,s_y1=150,s_x2=150,s_y2=250,s_x3=250,s_y3=250,s_x4=250,s_y4=150;

int s_centerx=200,s_centery=200;

int t_x1=200,t_y1=150,t_x2=245,t_y2=245,t_x3=155,t_y3=245;

int t_centerx=200,t_centery=210;

int f_centerx=150,f_centery=250,f_sa=60,f_ea=120,radius=50;

int f_x1=125,f_y1=207,f_x2=175,f_y2=207;

void drawSquare()

{

line(s_x1,s_y1,s_x2,s_y2);

line(s_x2,s_y2,s_x3,s_y3);

line(s_x3,s_y3,s_x4,s_y4);

line(s_x4,s_y4,s_x1,s_y1);

}

void drawTriangle()

{

line(t_x1,t_y1,t_x2,t_y2);

line(t_x2,t_y2,t_x3,t_y3);

line(t_x3,t_y3,t_x1,t_y1);

}

void drawFan()

{

arc(f_centerx,f_centery,f_sa,f_ea,radius);

line(f_x1,f_y1,f_centerx,f_centery);

line(f_x2,f_y2,f_centerx,f_centery);

}

void convert(int *x,int *y,int xc,int yc,double _angle)

{

int xt=*x,yt=*y;

*x=(int)(xc+(xt-xc)*cos(_angle)-(yt-yc)*sin(_angle));

*y=(int)(yc+(yt-yc)*cos(_angle)+(xt-xc)*sin(_angle));

}

void rotate(int angle,int choice)

{

double _angle=angle*PI/180;

if(choice==1)

{

convert(&s_x1,&s_y1,s_centerx,s_centery,_angle);

convert(&s_x2,&s_y2,s_centerx,s_centery,_angle);

convert(&s_x3,&s_y3,s_centerx,s_centery,_angle);

convert(&s_x4,&s_y4,s_centerx,s_centery,_angle);

}

else

{

if (choice==2)

{

convert(&t_x1,&t_y1,t_centerx,t_centery,_angle);

convert(&t_x2,&t_y2,t_centerx,t_centery,_angle);

convert(&t_x3,&t_y3,t_centerx,t_centery,_angle);

}

else

{

convert(&f_x1,&f_y1,f_centerx,f_centery,_angle);

convert(&f_x2,&f_y2,f_centerx,f_centery,_angle);

f_sa-=angle,f_ea-=angle;

}

}

}

int main()

{

int graphdriver = DETECT, graphmode;

int choice,angle;

initgraph(&graphdriver, &graphmode, "..\\bgi");

printf("*******************\n");

printf("1 draw square\n");

printf("2 draw triangle\n");

printf("3 draw fan\n");

printf("4 exit\n");

printf("*******************\n");

printf("please input a number to select your operation\n");

scanf("%d",&choice);

switch (choice)

{

case 1:drawSquare();break;

case 2:drawTriangle();break;

case 3:drawFan();break;

default: {closegraph();return 0;}

}

printf("please input a number(between 0 and 360) to rotate\n");

scanf("%d",&angle);

rotate(angle,choice);

switch (choice)

{

case 1:drawSquare();break;

case 2:drawTriangle();break;

case 3:drawFan();break;

}

getch();

return 0;

}

程序如上,我已經運行過了,可以運行,有問題我可以傳給妳源文件,和上面的也是壹樣。

  • 上一篇:我現在在電網,七八萬壹年,環境不喜,真心請教學java,跟在電網,未來哪個更好?隨便回答的絕不采納
  • 下一篇:迫擊炮能夠把炮彈發射得那麽遠
  • copyright 2024編程學習大全網