#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
void DrawRect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
void Rotate(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, float angle);
int main()
{
int gd = DETECT, gm;
int x1, y1, x2, y2, x3, y3, x4, y4;
float angle;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
printf("Enter the 1st point for the rect (x1 y1): ");
scanf("%d%d", &x1, &y1);
printf("Enter the 2nd point for the rect (x2 y2): ");
scanf("%d%d", &x2, &y2);
printf("Enter the 3rd point for the rectangle (x3 y3): ");
scanf("%d%d", &x3, &y3);
printf("Enter the 4rd point for the rect (x4 y4): ");
scanf("%d%d", &x4, &y4);
DrawRect(x1, y1, x2, y2, x3, y3, x4, y4);
printf("Enter the angle for rotation (in degrees): ");
scanf("%f", &angle);
Rotate(x1, y1, x2, y2, x3, y3,x4,y4, angle);
getch();
closegraph();
return 0;
}
void DrawRect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x4, y4);
line(x4, y4, x1, y1);
}
void Rotate(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, float angle)
{
int p = x2, q = y2;
float radianAngle = (angle * 3.14) / 180.0;
int a1 = p + (x1 - p) * cos(radianAngle) - (y1 - q) * sin(radianAngle);
int b1 = q + (x1 - p) * sin(radianAngle) + (y1 - q) * cos(radianAngle);
int a2 = p + (x2 - p) * cos(radianAngle) - (y2 - q) * sin(radianAngle);
int b2 = q + (x2 - p) * sin(radianAngle) + (y2 - q) * cos(radianAngle);
int a3 = p + (x3 - p) * cos(radianAngle) - (y3 - q) * sin(radianAngle);
int b3 = q + (x3 - p) * sin(radianAngle) + (y3 - q) * cos(radianAngle);
int a4 = p + (x4 - p) * cos(radianAngle) - (y4 - q) * sin(radianAngle);
int b4 = q + (x4 - p) * sin(radianAngle) + (y4 - q) * cos(radianAngle);
setcolor(1);
DrawRect(a1, b1, a2, b2, a3, b3, a4, b4);
}