You are on page 1of 3

Source code programming 2D TRANSFORMATION Coding

#include <stdio.h>
#include <stdlib.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void draw2d(int,int [],int [],int,int);
void main()
{
int gd=DETECT,gm;
int x[20],y[20],tx=0,ty=0,i,fs;
initgraph(&gd,&gm,"");
printf("No of sides : ");
scanf("%d",&fs);
printf("Co-ordinates : ");
for(i=0;i<fs;i++)
{
printf("(x%d,y%d)",i,i);
scanf("%d%d",&x[i],&y[i]);
}
draw2d(fs,x,y,tx,ty);
printf("translation (x,y) : ");
scanf("%d%d",&tx,&ty);
draw2d(fs,x,y,tx,ty);
getch();
}
void draw2d(int fs,int x[20],int y[20],int tx,int ty)
{
int i;
for(i=0;i<fs;i++)
{
if(i!=(fs-1))
line(x[i]+tx,y[i]+ty,x[i+1]+tx,y[i+1]+ty);
else
line(x[i]+tx,y[i]+ty,x[0]+tx,y[0]+ty);
}
}
//# Author: J.Ajai
//#Mail-id- ajay.compiler@gmail.com
//# PH:+91-9790402155
OUTPUT
2D TRANSFORMATION
--------------------------------------------------1.Translation

2.Scaling
3.Shearing
4.Reflection

5.Rotation

Enter your Choice :1


2D TRANSFORMATION
--------------------------------------------------1.Translation

2.Scaling
3.Shearing
4.Reflection
5.Rotation
Enter your Choice :2
SEE THE FOLLOWING OUTPUT SCALING, SHEARING WITH 2
DIGARM(Shearing Y direction with respect to Xref &,Shearing x direction with
respect to yref)
Source coding Output REFLECTION & ROTATION 2D TRANSFORMATION

You might also like