0% found this document useful (0 votes)
65 views2 pages

2D Rotation

This C program rotates a 2D line about a point by a user-specified degree. It takes the x1, y1 and x2, y2 coordinates of the original line as input, draws the line, then takes a degree of rotation as input. It converts the degree to radians, calculates the new x2 and y2 coordinates using trigonometric functions of the original endpoints, and draws the rotated line.

Uploaded by

Saumayshri Nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views2 pages

2D Rotation

This C program rotates a 2D line about a point by a user-specified degree. It takes the x1, y1 and x2, y2 coordinates of the original line as input, draws the line, then takes a degree of rotation as input. It converts the degree to radians, calculates the new x2 and y2 coordinates using trigonometric functions of the original endpoints, and draws the rotated line.

Uploaded by

Saumayshri Nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h
>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT, r, gm, d, x1, y1, x2, y2, xn1, yn1, xn2, yn2;
float ra, si, co;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
printf("Enter the value of X1 and Y1: ");
scanf("%d %d", &x1, &y1);
printf("Enter the value of X2 and Y2: ");
scanf("%d %d", &x2, &y2);
line(x1, y1, x2, y2);
printf("Enter the degree of rotation: ");
scanf("%d", &d);
//Starting point would be same
xn1 = x1;
yn1 = y1;
//Convert Degree into radian
r = x2-x1;
ra = 0.0175 * d;
si = sin(ra);
co = cos(ra);
//second point
xn2 = x1 + r*co + 1;
yn2 = y1 + r*si + 1;
line(xn1, yn1, xn2, yn2);
getch();
closegraph();
}

view rawRotate_A_2D_Object_Using_C_Graphics.c hosted with   by GitHub

Output
Enter the value of X1 and Y1: 100 100

Enter the value of X2 and Y2: 200 100

Enter the degree of rotation: 90

You might also like