HOT C PROGRAMS BLOGSPOT

HOT C PROGRAMS BLOGSPOT

Click On Related Results For More Information

Saturday 13 October 2012

Graphics Line Rotation C Program

 /*   .......Works on Win XP      */
 /*   Graphics Line Rotation Rotate C Program  */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#define pi 3.1456
void rotation(int,int,float);
int x1,y1,x2,y2,x3,y3,xf,yf,a;
float b;
void rotation(int xf,int yf,float b)
{
setcolor(GREEN);
line((x1*cos(b)-y1*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x1*sin(b)+y1*cos(b)-xf*sin(b)-yf*cos(b)+yf),(x2*cos(b)-y2*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x2*sin(b)+y2*cos(b)-xf*sin(b)-yf*cos(b)+yf));
line((x2*cos(b)-y2*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x2*sin(b)+y2*cos(b)-xf*sin(b)-yf*cos(b)+yf),(x3*cos(b)-y3*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x3*sin(b)+y3*cos(b)-xf*sin(b)-yf*cos(b)+yf));
line((x1*cos(b)-y1*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x1*sin(b)+y1*cos(b)-xf*sin(b)-yf*cos(b)+yf),(x3*cos(b)-y3*sin(b)-xf*cos(b)+yf*sin(b)+xf),(x3*sin(b)+y3*cos(b)-xf*sin(b)-yf*cos(b)+yf));
}
void main(void)
{
int gd=DETECT,gm;
clrscr();
printf("enter 1st point=");
scanf("%d %d",&x1,&y1);
printf("\n enter 2nd point=");
scanf("%d %d",&x2,&y2);
printf("\n enter3rd point=");
scanf("%d %d",&x3,&y3);
printf("enter reference point=");
scanf("%d %d",&xf,&yf);
printf("enter the angle=");
scanf("%d",&a);
b=(pi*a)/180.0;
initgraph(&gd,&gm,"c:\\tc\\bgi");   /*Sometimes it may be  "C:\\TC\\BGI"  , It depends machine to mac..*/
setcolor(WHITE);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3) ;
line(x1,y1,x3,y3);
rotation(xf,yf,b);
getch();
closegraph();
}





1 comment: