C Grpahics – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Sat, 20 Aug 2022 15:13:27 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg C Grpahics – Programmerbay https://programmerbay.com 32 32 C Program for 2D Translation https://programmerbay.com/c-program-for-2d-translation/ https://programmerbay.com/c-program-for-2d-translation/#respond Fri, 19 Aug 2022 09:55:19 +0000 https://www.programmerbay.com/?p=1837 2D Translation can be defined as a way of shifting an object from one point to another in a straight path. Here is the C program for demonstrating 2D translation

Must Read: What is 2D Translation?

Program to show the translation of a line

Program:

#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
// declaring two array
// Translation vector already initialized
int l[2][2],v[2]={10,15},i=0,j;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("Enter the initial and final coordinates of a line ");

// Getting input from user, having 2D array where 1st row represents initial point
// And Second row represents final coordinate
while(i<2)
{
printf("x%d and y%d = ",i,i);
j=0;
scanf("%d",&l[i][j]);
scanf("%d",&l[i][j+1]);
i++;
}
// Line before translation
line(l[0][0],l[0][1],l[1][0],l[1][1]);
setcolor(BLUE);
// Line after translation
line(l[0][0]+v[0],l[0][1]+v[1],l[1][0]+v[0],l[1][1]+v[1]); // Adding Translation vector in it to change the position
getch();
closegraph();
}

 

Output:

translation using array

 

 

Related post with Example:

2D Translation: Positioning of an Object

]]>
https://programmerbay.com/c-program-for-2d-translation/feed/ 0