triangle – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Sat, 20 Aug 2022 18:15:08 +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 triangle – 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 to Perform Shearing on Triangle https://programmerbay.com/c-program-to-perform-shearing-on-a-triangle/ https://programmerbay.com/c-program-to-perform-shearing-on-a-triangle/#respond Mon, 01 Aug 2022 11:55:53 +0000 https://www.programmerbay.com/?p=1928 In this article, we’ll be implementing shearing transformation program with output. In Transformation, shearing is the process of slanting the shape of an object.

C Program to perform shearing of a triangle along the x axis with output

Program:

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
int x,y,x1,y1,x2,y2,shear_f;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("\n please enter first coordinate = ");
scanf("%d %d",&x,&y);
printf("\n please enter second coordinate = ");
scanf("%d %d",&x1,&y1);
printf("\n please enter third coordinate = ");
scanf("%d %d",&x2,&y2);
printf("\n please enter shearing factor x = ");
scanf("%d",&shear_f);
cleardevice();
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);

setcolor(RED);
x=x+ y*shear_f;
x1=x1+ y1*shear_f;
x2=x2+ y2*shear_f;

line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
getch();
closegraph();
}

 

Output:

triangle shearing x

C Program to perform shearing of a triangle along the y axis with output

Program:

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
int x,y,x1,y1,x2,y2,shear_f;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("\n please enter first coordinate = ");
scanf("%d %d",&x,&y);
printf("\n please enter second coordinate = ");
scanf("%d %d",&x1,&y1);
printf("\n please enter third coordinate = ");
scanf("%d %d",&x2,&y2);
printf("\n please enter shearing factor y = ");
scanf("%d",&shear_f);
cleardevice();
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);

setcolor(RED);
y=y+ x*shear_f;
y1=y1+ x1*shear_f;
y2=y2+ x2*shear_f;

line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
getch();
closegraph();
}

Output:

triangle shearing y

]]>
https://programmerbay.com/c-program-to-perform-shearing-on-a-triangle/feed/ 0