-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCubeRotaionAboutCentroid
82 lines (66 loc) · 1.72 KB
/
CubeRotaionAboutCentroid
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
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#define ORG -50
double cx=320,cy=320;
double face1[5][2] = {
{ 320-50, 240-50 },
{ 320+50, 240-50 },
{ 320+50, 240+50 },
{ 320-50, 240+50 },
{ 320-50, 240-50 }
};
double face2[5][2] = {
{ 320-50+ORG, 240-50-ORG },
{ 320+50+ORG, 240-50-ORG },
{ 320+50+ORG, 240+50-ORG },
{ 320-50+ORG, 240+50-ORG },
{ 320-50+ORG, 240-50-ORG }
};
double angle = -5.0 * M_PI / 180;
double midx1, midy1, midx2, midy2;
void rotate (void)
{
int i;
for (i=0; i<5; i++)
{
double xnew, ynew;
xnew = midx1 + (face1[i][0] - midx1) * cos (angle) -
(face1[i][1] - midy1) * sin (angle);
ynew = midy1 + (face1[i][0] - midx1) * sin (angle) +
(face1[i][1] - midy1) * cos (angle);
face1[i][0] = xnew;
face1[i][1] = ynew;
xnew = midx2 + (face2[i][0] - midx2) * cos (angle) -
(face2[i][1] - midy2) * sin (angle);
ynew = midy2 + (face2[i][0] - midx2) * sin (angle) +
(face2[i][1] - midy2) * cos (angle);
face2[i][0] = xnew;
face2[i][1] = ynew;
}
cleardevice();
for (i=0; i<4; i++)
{
setcolor(9);
line (face1[i][0], face1[i][1], face1[i+1][0], face1[i+1][1]);
line (face2[i][0], face2[i][1], face2[i+1][0], face2[i+1][1]);
line (face1[i][0], face1[i][1], face2[i][0], face2[i][1]);
}
delay (125);
}
int main()
{
int gd = DETECT, gm;
midx1 = (face1[0][0] + face1[1][0]) / 2.0;
midy1 = (face1[1][1] + face1[2][1]) / 2.0;
midx2 = (face2[0][0] + face2[1][0]) / 2.0;
midy2 = (face2[1][1] + face2[2][1]) / 2.0;
initgraph (&gd, &gm, "");
setbkcolor(WHITE);
while (!kbhit())
rotate();
closegraph();
}