Tuesday, 28 September 2021

Implement Translation of a line in C Language

To translate a point from coordinate position (x, y) to another (x1 y1), we add algebraically the translation distances Tx and Ty to original coordinate.

x1=x+Tx
y1=y+Ty

The translation pair (Tx,Ty) is called as shift vector.

Translation is a movement of objects without deformation. Every position or point is translated by the same amount. When the straight line is translated, then it will be drawn using endpoints.

For translating polygon, each vertex of the polygon is converted to a new position. Similarly, curved objects are translated. To change the position of the circle or ellipse its center coordinates are transformed, then the object is drawn using new coordinates.


Implement Translation of a line in C Language


Code:-


#include <stdio.h>

#include <conio.h>

#include <graphics.h>

void main(void)

{ int gdriver=DETECT,gmode,X1,Y1,X2,Y2,TX,TY;

  initgraph(&gdriver,&gmode,"C:\\TURBOC3\\BGI");

  printf("\n Enter The Value of Initial X1 Axis: \n");

  scanf("%d",&X1);

  printf("\n Enter The Value of Initial Y1 Axis: \n");

  scanf("%d",&Y1);

  printf("\n Enter The Value of Initial X2 Axis: \n");

  scanf("%d",&X2);

  printf("\n Enter The Value of Initial Y2 Axis: \n");

  scanf("%d",&Y2);

  printf("\n Enter The Value of TRANSLATION VECTOR TX Axis: \n");

  scanf("%d",&TX);

  printf("\n Enter The Value of TRANSLATION VECTOR TY Axis: \n");

  scanf("%d",&TY);

  clrscr();

  setbkcolor(WHITE);

  setcolor(2);

  outtextxy(X1,Y1+5 ,"Before Translation Process");

  line(X1,Y1,X2,Y2);

  X1 = X1 + TX;

  Y1 = Y1 + TY;

  X2 = X2 + TX;

  Y2 = Y2 + TY;

  setcolor(5);

  outtextxy(X1,Y1+5,"After Translation Process");

  line(X1,Y1,X2,Y2);

  getch();

  closegraph();

}


Output:-



- Anupam Dutta

CSE(2020-2023)

JIS College Of Engineering, Kalyani (JISCE)

No comments:

Post a Comment