-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcentroid.cpp
More file actions
46 lines (37 loc) · 893 Bytes
/
centroid.cpp
File metadata and controls
46 lines (37 loc) · 893 Bytes
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
#include <graphics.h>
#include "transforms.h"
#define DELAY_TIME 2000 //Microseconds
void init(void)
{
int gd=DETECT;
int gm;
initgraph(&gd, &gm, NULL);
}
void draw(void)
{
int points[]={150, 150, 200, 200, 200, 150, 150, 150};
int n = 4;
mypolygon(points, n);
int centroid_x = (points[0]+points[2]+points[4])/3.0;
int centroid_y = (points[1]+points[3]+points[5])/3.0;
float I[3][3]; toIdentity(I);
float T[3][3];
translateMat(T, -centroid_x, -centroid_y); combine(T, I);
scaleMat(T, 2, 2); combine(T, I);
rotateMat(T, 90); combine(T, I);
translateMat(T, centroid_x, centroid_y); combine(T, I);
valMat(I, points, n);
mypolygon(points, n);
}
void end(void)
{
while(getchar() == 0); // Don't close it
closegraph();
}
int main(int args, char *argv[])
{
init(); // Initialise
draw(); // Draw on the graph
end();
return 0;
}