0% found this document useful (0 votes)
101 views2 pages

2D Rotation

This document contains a C program for performing two-dimensional rotation transformations on a polygon defined by its edges. It includes functions for rotation based on user-defined angle and center of rotation, as well as graphics initialization and drawing. The program prompts the user for input regarding the polygon's edges and rotation parameters.

Uploaded by

ansarikashifx7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views2 pages

2D Rotation

This document contains a C program for performing two-dimensional rotation transformations on a polygon defined by its edges. It includes functions for rotation based on user-defined angle and center of rotation, as well as graphics initialization and drawing. The program prompts the user for input regarding the polygon's edges and rotation parameters.

Uploaded by

ansarikashifx7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICAL NO: 08

Q) Write a program in C for two dimensional transformation (Rotation).


Code:
#include<stdio.h> for(int i=0;i<edges;i++)
#include<conio.h> {
#include<graphics.h> printf("enter edge (x%d,y%d):",i,i);
#include<math.h> scanf("%d%d",&figure[2*i],&figure[2*
void rotate(int figure[],int edges,double i+1]);
angle,int cx,int cy) }
{ figure[2*i]=figure[0];
double x,y; figure[2*i+1]=figure[1];
angle=-1*(angle*3.14/180); edges+=1;
double cos_a=cos(angle); printf("Enter angle of rotation in
double sin_a=sin(angle); degrees:");
for(int i=0;i<edges;i++) scanf("%lf",&angle);
{ printf("Enter the center of
x=figure[2*i]-cx; rotation:\n");
y=figure[2*i+1]-cy; printf("cx:");
figure[2*i]=ceil((x*cos_a)- scanf("%d",&cx);
(y*sin_a)+cx); printf("cy:");
figure[2*i+1]=ceil((x*sin_a)+(y*cos_a) scanf("%d",&cy);
+cy); cy=max_y-cy;
} cleardevice();
} setbkcolor(WHITE);
void main() setcolor(GREEN);
{ setlinestyle(SOLID_LINE,0,3);
int figure[20],edges; drawpoly(edges,figure);
double angle; getch();
int cx=0,cy=0; for(i=0;i<edges;i++)
int gd,gm; figure[2*i+1]=max_y-figure[2*i+1];
detectgraph(&gd,&gm); rotate(figure,edges,angle,cx,cy);
initgraph(&gd,&gm,"C:\\TC\\BGI"); for(i=0;i<edges;i++)
int max_y=getmaxy(); figure[2*i+1]=max_y-figure[2*i+1];
clrscr(); setcolor(RED);
cleardevice(); drawpoly(edges,figure);
printf("Enter Number of Edges:"); getch();
scanf("%d",&edges); }
PRACTICAL NO: 08
Output:

You might also like