translation – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Sat, 20 Aug 2022 18:25:07 +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 translation – Programmerbay https://programmerbay.com 32 32 C Program for Translation of a Triangle https://programmerbay.com/c-program-for-translation-of-a-triangle/ https://programmerbay.com/c-program-for-translation-of-a-triangle/#respond Fri, 19 Aug 2022 14:44:00 +0000 https://www.programmerbay.com/?p=1843 triangle

A Triangle is made up of three vertices or points in which three line segments are joined together.

Here is the snippet.

Program for Translation of a Triangle in C

Program:

/* translation */
#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
int x,y,x1,y1,x2,y2,tx,ty;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("\n Please enter first coordinate of the triangle= ");
scanf("%d %d", &x,&y);
printf("\n Enter second coordinate of the trinagle = ");
scanf("%d %d",&x1,&y1);
printf("\n Enter third coordinate of the triangle = ");
scanf("%d %d",&x2,&y2);
printf("\n\t\t********** TRIANGLE before & after translation ***********");
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
printf("\n Now enter the translation vector = ");
scanf("%d %d",&tx,&ty);

setcolor(RED);
line(x+tx,y+ty,x1+tx,y1+ty);
line(x1+tx,y1+ty,x2+tx,y2+ty);
line(x2+tx,y2+ty,x+tx,y+ty);
getch();
closegraph();
}

 

 

Output:

triangle translation

]]>
https://programmerbay.com/c-program-for-translation-of-a-triangle/feed/ 0
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
C Program to Show a Kite is Flying https://programmerbay.com/c-program-to-show-a-kite-is-flying/ https://programmerbay.com/c-program-to-show-a-kite-is-flying/#respond Wed, 03 Aug 2022 08:46:20 +0000 https://www.programmerbay.com/?p=1969 The program uses translation transformation to implement flying kite in C. In computer graphics, translation allows reposition of an object. We can create an illusion of flying kite by frequently changing the object’s position.

C Program to show a kite is flying

Program:

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
int gm,gd=DETECT;
int i= 0,j=0,rnd_x=0,rnd_y,stop_me=0;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
srand(time());
while(stop_me<=1000)
{

if(i>=180 &&j>=100 ) // controlling kite, so that it wouldn't disappear from screen
{
rnd_x=rand()%4 -3;
rnd_y=rand()%5 -4;
}
else{
rnd_x=rand()%3;
rnd_y=rand()%3;
}
line(200+i,200-j,250+i,250-j);
line(200+i,200-j,150+i,250-j);
line(150+i,250-j,200+i,350-j);
line(200+i,350-j,250+i,250-j);
line(200+i,200-j,200+i,350-j);
arc(200+i,275-j,25,155,50);
line(0,500,200+i,225-j);
i=i+rnd_x;
j=j+rnd_y;
stop_me=5+stop_me;
delay(100);
clearviewport(); // clearing image which would make illusion of flying kite

}
getch();
closegraph();

}

Output:

]]>
https://programmerbay.com/c-program-to-show-a-kite-is-flying/feed/ 0