forked from Ayushsinhahaha/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.py
123 lines (123 loc) · 2.86 KB
/
Rectangle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include<iostream.h>
#include <stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#define pi 3.14
class arc
{
float x[10], y[10], theta, h1, k1,r[0][10],ang;
float p[10][10],p1[10][10],x1[10], y1[10],xm,yx;
int i, k, j, n;
public:
void get();
void cal();
void map();
void graph();
void plot();
void plot1();
};
void arc::get()
{
cout "<<"\n ENTER ANGLE OF ROTATION ";
cin>>ang;
n = 4;
cout<<"\n ENTER";
for (i=0; i<n; i++)
{
cout<<"\n x["<i<<"] and y["<<i<<"]";
cin>>x[i]>>y[i];
}
h1=x [0] + (([1]-x[0])/2);
k1=y[0]+(([3]-y[0])/2);
cout<<"\n MIDPOINT OF RECTANGLE IS--"<<h1<<"\t"<<k1;
theta=(ang*pi)/180?;
r[0][0]=cos (theta);
r[0][1]= -sin?(theta);
r[0][2]=(-h1*cos(theta))+(k1*sin(theta)+h1;
r[1][0]=sin (theta);
r [1][1]=cos (theta);
r [1][2]=(-h1*sin(theta))+(-k1*cos(theta)+k1;
r[2][0]=0;
r[2][1]=0;
r[2][2]=1;
}
void arc ::cal()
{
for(i=0;i<n;i++)
{
p[0][i]=x[i];
p[1][i]=y[i];
p[2][i]=1;
}
for(i=0;i<3;i++)
{
for(j=0;j<n;j++)
{
p1[i][j]=0;
for (k=0;k<3;k++)
{
p1[i][j]+=r[i][k]*p[k][j];
}
}
}
for(i=0;i<n;i++)
{
x1[i]=p1[0][i];
y1[i]=p[1][i];
}
}
void arc::map()
{
int gd=DETECT, gm;
initgraph (&gd, &gm, "");
int errorcode = graphresult();
/*an error occurred */
if (errorcode!=grOK)
{
printf("Graphics error: %s \n",grapherrormsg (errorcode));
printf("Press and key to halt: ");
getch();
exit(1); /* terminate with an error code */
}
}
void arc::graph()
{
xm=getmaxx()/2;
ym=getmaxy()/2;
line (xm, 0, xm, 2 * ym);
line (0, ym, 2 * xm, ym);
}
void arc :: plot 1()
{
for (i=0;i<n-1;i++)
{
circle (x1[i]+xm, (-y1[i]+ym), 2);
line (x1[i]+xm, (-y1[i]+ym), x[i+1] xm, (-y1[0]+ym));
}
line (x1[n-1] +xm, (-y1[n-1]+ym), x1[0]+xm, (-y1[0]+ym));
getch();
}
void arc :: plot ()
{
for (i=0;i<n-1;i++)
{
circle (x[i]+xm, (-y[i]+ym), 2);
line (x[i]+xm, (-y[i]+ym), x[i+1] xm, (-y[i+1]+ym));
}
circle (x[n-1]+xm, (-y[n-1]+ym),2);
line (x[n-1]+xm, (-y[n-1]+ym), x[0]+xm, (-y[0]+ym));
getch();
}
void main ()
{
class arc a;
clrscr();
a.map();
a.graph();
a.get();
a.cal();
a.plot();
a.plot1();
getch();
}