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

2D Rotation Program Updated

The document describes a 2D rotation program in C language that rotates points around the origin by a specified angle θ. It includes the rotation formulas, an algorithm for implementation, and a sample code demonstrating the process of inputting points and calculating their new coordinates after rotation. The program takes user input for the number of points, their coordinates, and the rotation angle, then outputs the rotated coordinates.

Uploaded by

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

2D Rotation Program Updated

The document describes a 2D rotation program in C language that rotates points around the origin by a specified angle θ. It includes the rotation formulas, an algorithm for implementation, and a sample code demonstrating the process of inputting points and calculating their new coordinates after rotation. The program takes user input for the number of points, their coordinates, and the rotation angle, then outputs the rotated coordinates.

Uploaded by

yashcentral37
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

2D Rotation Program (C Language)

2D rotation is a transformation in computer graphics where an object is rotated by an angle θ about


the origin.

Rotation Formula:
x' = x cosθ - y sinθ
y' = x sinθ + y cosθ

Algorithm:
1. Start
2. Input number of points (n)
3. Input coordinates (x, y) for each point
4. Input rotation angle θ (in degrees)
5. Convert θ into radians
6. For each point:
a. Compute x' = x cosθ - y sinθ
b. Compute y' = x sinθ + y cosθ
7. Display rotated coordinates
8. Stop

Diagram (Rotation about Origin):

(x',y') (x,y)

#include <stdio.h>
#include <math.h>

int main() {
int n, i;
float x[10], y[10];
float angle, rad;

printf("Enter number of points: ");


scanf("%d", &n);

for(i = 0; i < n; i++) {


printf("Enter x and y for point %d: ", i+1);
scanf("%f %f", &x[i], &y[i]);
}

printf("Enter rotation angle (in degrees): ");


scanf("%f", &angle);

rad = angle * (M_PI / 180);

printf("\nRotated Points:\n");
for(i = 0; i < n; i++) {
float x_new = x[i] * cos(rad) - y[i] * sin(rad);
float y_new = x[i] * sin(rad) + y[i] * cos(rad);

printf("Point %d -> (%.2f, %.2f)\n", i+1, x_new, y_new);


}

return 0;
}

You might also like