-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVEX_Circle
71 lines (61 loc) · 1.58 KB
/
VEX_Circle
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
// Controls
float radius = ch('radius');
int nbPoints = max(3, chi('points'));
vector origin = chv('origin');
string dir = chs('direction');
string gap = chs('gap');
// Variables
float theta;
float step_theta = 2*PI / nbPoints;
float u, v;
float x, y, z;
vector curPos;
int points[];
resize(points, nbPoints);
// Building circle
for (int i = 0; i < nbPoints; i++) {
// Coordinates in circle's perspective
theta = i * step_theta;
u = radius * cos(theta);
v = radius * sin(theta);
// Coordinates depending on direction
if (dir == "x") {
x = origin.x;
y = u + origin.y;
z = v + origin.z;
}
if (dir == "y") {
x = u + origin.x;
y = origin.y;
z = v + origin.z;
}
if (dir == "z") {
x = u + origin.x;
y = v + origin.y;
z = origin.z;
}
// Adding current position
curPos = set(x, y, z);
points[i] = addpoint(0, curPos);
// Adding Edges
if (i>0) {
addprim(0, "polyline", points[i-1], points[i]);
}
}
// Edge between last point and first point
addprim(0, "polyline", points[nbPoints-1], points[0]);
// Gap with one polygone
if (gap == "1") {
addprim(0, "poly", points);
}
// Gap with a center point
if (gap == "2") {
int center = addpoint(0, origin);
for (int i = 0; i < nbPoints; i++) {
addprim(0, "polyline", center, points[i]);
}
for (int i = 1; i < nbPoints; i++) {
addprim(0, "poly", center, points[i-1], points[i]);
}
addprim(0, "poly", center, points[nbPoints-1], points[0]);
}