rotation in computer graphics – 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 rotation in computer graphics – 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