Friday, May 14, 2010

2 Dimensional Translation in C program | CS1355-Graphics & Multimedia Lab

Translation is a simple straight line movement of the object in x and y direction. We define an image in coordinate system, to display that image Or object. Transformation is refer to transform from one position to another position depends upon there transformation it is classified into.Scaling.Shearing.Reflection.Rotation see the source code in C coding
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 :12D TRANSFORMATION  in c program  computer graphics lab
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
2D TRANSFORKMATION  in c program  computer graphics lab

2D TRANSFORKMATION  in c program  computer graphics lab 2D TRANSFORKMATION  in c program  computer graphics lab 2D TRANSFORKMATION  in c program  computer graphics lab2D TRANSFORKMATION  in c program  computer graphics lab

0 comments:

Flag counter

free counters