C program to tramsform 2D objects.

Posted by Mangesh on May 03, 2018

/* program for transforming 2D object. */

Description :

Transforming a 2D object from one location to another can be done by adding the transforming factors to actual coordinates.

Program :

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main() {
   int gdriver = DETECT, gmode;
   int point[] = {50,50,50,200,200,200,50,50};
   int i,sx,sy;
   initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
   drawpoly(4,point);
   printf("\n\nEnter the transform factor of X - axis : ");
   scanf("%d",&sx);
   printf("Enter the transform factor of Y - axis : ");
   scanf("%d",&sy);

   for(i=0;i<8;i++)
   {
     if(i%2==0)
       point[i] = point[i] + sx;
     else
       point[i] = point[i] + sy;
   }
   drawpoly(4,point);
   getch();
   closegraph();
}

Output :

 c program for transform 2d object output Executed and tested in Turbo C 3.2

Written with from Mangesh.

Related Post
1 C program for scaling of 2D object.
2 C program to tramsform 2D objects.
3 C program to draw a line.
4 C program to draw a circle.
5 C program to draw a rectangle.
6 C program for DDA algorithm to generate line.
7 C program for midpoint circle algorithm.
8 C program to draw a bar graph.
9 C program for bresenham's circle drawing algorithm.
Latest Post
1 shubhanshu
2 test
3 C program for Breadth First Search.
4 C program for Depth First Search(DFS).
5 C for circular queue using linked list.