2d – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Sat, 20 Aug 2022 15:16:31 +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 2d – Programmerbay https://programmerbay.com 32 32 C Program to Rotate a Line https://programmerbay.com/c-program-to-rotate-a-line/ https://programmerbay.com/c-program-to-rotate-a-line/#respond Wed, 27 Jul 2022 12:48:40 +0000 https://www.programmerbay.com/?p=1863 Rotation can be defined as moving an object in a circular path at a given angle theta.

If there is a positive angle, it would rotate in anticlockwise whereas if it appears to a negative angle, the object would rotate in clockwise. Here’s is C program to rotate a line in computer Graphics. The below program is rotation program in C.

Program to show rotation of a line in Computer Graphics

Program:

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
int pivot_x,pivot_y,x,y;
double degree,radian;
int rotated_point_x,rotated_point_y;
initgraph(&gd,&gm,"C://TURBOC3//BGI");
cleardevice();
printf("\t\t*********** ROTATION *********** \n");
printf("\n Enter an initial coordinates of the line = ");
scanf("%d %d",&pivot_x,&pivot_y);
printf("\n Enter a final coordinates of the line = ");
scanf("%d %d",&x,&y);
line(pivot_x,pivot_y,x,y);
printf("\n\n Now, Enter a degree = ");
scanf("%lf",&degree);
radian=degree*0.01745;
rotated_point_x=(int)(pivot_x +((x-pivot_x)*cos(radian)-(y-pivot_y)*sin(radian)));
rotated_point_y=(int)(pivot_y +((x-pivot_x)*sin(radian)+(y-pivot_y)*cos(radian)));
setcolor(RED);
line(pivot_x,pivot_y,rotated_point_x,rotated_point_y);
getch();
closegraph();
}

 

Output:

Rotation by 30

rotation 30

Rotation by 90

rotation 90

]]>
https://programmerbay.com/c-program-to-rotate-a-line/feed/ 0
Types of Transformations in Computer Graphics https://programmerbay.com/what-is-2d-transformation-in-c-graphics/ https://programmerbay.com/what-is-2d-transformation-in-c-graphics/#respond Thu, 14 Jul 2022 17:57:24 +0000 https://programmerbay.com/?p=5145 Transformation

Transformation can be defined as repositioning of coordinates, size or orientation of an object. There are various types of transformations namely translation, rotation scaling, etc. A transformation can be 2D and 3D. In this, We will study about 2D transformation that forms using (x,y) coordinates


Types of Transformations

In computer graphics, there are various types of transformation :

Translation
Rotation
Scaling
Reflection
Shearing

Translation

A translation is a repositioning of an object along a straight line by adding a translation factor to the original coordinates of the given object.
A translation factor is also known as the translation vector.
Suppose, (x,y) is a position of an object. (tx,ty) is a translation vector that to be added to the given coordinate (x,y). After adding them, the object would be placed at a new coordinate.

x’=x+tx ,

y’=y+ty

Rotation

Rotation can be defined as moving an object in a circular path at a given angle theta. if there is a positive angle, it would rotate in anticlockwise whereas if it appears to a negative angle, the object would rotate in clockwise. The point at which an object about to rotate is known as a pivot point.

x’= x cosθ – y sinθ

y’= x sinθ + y cosθ

Scaling

Scaling is a redefining the size of an object or changing the size of an object by multiplying scaling factor to it.
x’ = x*Sx ,

y’=y.Sy

Reflection

Reflection has nothing to do with size, it is a repositioning of an object relative to xy quadrants that produce a mirror image.

Shear

Shearing is a process of slanting the edges of an object. it can be of two types x shear and y shear
In x-shear, we don’t touch y-coordinates, but changes are made to x coordinate which produces a  right or left tilted object
In y shear, we don’t touch x coordinate, instead, changes are made to x coordinate which produces a right or left tilted object

]]>
https://programmerbay.com/what-is-2d-transformation-in-c-graphics/feed/ 0