-
Notifications
You must be signed in to change notification settings - Fork 1
/
stippling_util.h
205 lines (157 loc) · 3.99 KB
/
stippling_util.h
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#pragma once
arr center(arr pts) { return pts; }
arr scale(arr pts) { return pts; }
std::map<uint, arr>
overlappingCircles(const uint n1 = 25, const uint n2 = 25,
const double r1 = 0.05, const double r2 = 0.05,
const double x1 = -0.03, const double x2 = 0.03,
const double y1 = 0, const double y2 = 0) {
std::map<uint, arr> res;
arr pts;
for (uint i = 0; i < n1; ++i) {
const arr pt = {x1 + r1 * sin(2. * i / n1 * 3.1415),
y1 + r1 * cos(2. * i / n1 * 3.1415)};
pts.append(pt);
}
pts.reshape(-1, 2);
res[0] = pts;
pts.clear();
for (uint i = 0; i < n2; ++i) {
const arr pt = {x2 + r2 * sin(2. * i / n2 * 3.1415),
y2 + r2 * cos(2. * i / n2 * 3.1415)};
pts.append(pt);
}
pts.reshape(-1, 2);
res[1] = pts;
return res;
}
arr grid(const uint nx = 5, const uint ny = 5, const double x = 0.3,
const double y = 0.3) {
arr pts;
for (uint i = 0; i < nx; ++i) {
for (uint j = 0; j < ny; ++j) {
const arr point = {1. * i / (nx - 1) * x - x / 2,
1. * j / (ny - 1) * y - y / 2};
pts.append(point);
}
}
pts.reshape(-1, 2);
return pts;
}
arr greedy_counterexample(){
return grid(2, 2, 0.01, 0.4);
}
arr spiral(const uint n = 20) {
arr pts;
for (uint i = 0; i < n; ++i) {
const arr pt = {0.25 * (i + 1) / n * sin(i * 2 / 3.1415),
0.25 * (i + 1) / n * cos(i * 2 / 3.1415)};
pts.append(pt);
}
pts.reshape(-1, 2);
return pts;
}
arr circles(const double x = 0.25, const uint num = 8) {
arr pts;
for (uint j = 0; j < num + 1; ++j) {
double r = 0.5 * x * (1. - 1. * j * j / (num * num));
uint n = (num - j) * (num - j) + 1;
double phi = (rand() % 1000) / 1000.;
// std::cout << r << " " << n << std::endl;
for (uint i = 0; i < n; ++i) {
const arr pt = {r * sin(phi + i * 2 * 3.1415 / n),
r * cos(phi + i * 2 * 3.1415 / n)};
pts.append(pt);
}
}
pts.reshape(-1, 2);
return pts;
}
arr cube(const uint n = 200) {
arr v = {1, 1, 1};
v = v / length(v);
arr R;
rotationFromAtoB(R, {0, 0, 1}, v);
rai::Configuration C;
arr pts;
for (uint i = 0; i < n; ++i) {
arr pt(3, 1);
rndUniform(pt, -1, 1);
const uint ind = rand() % 3;
// const uint sign = rand() % 2;
const uint sign = 1;
pt[ind] = sign * 2. - 1;
// rotate
pt = R * pt;
// scale down
pt = pt * 0.07;
// project
const arr pt_proj = {pt[0](0), pt[1](0)};
pts.append(pt_proj);
auto *dot = C.addFrame("dot", "");
dot->setShape(rai::ST_sphere, {0.005});
dot->setPosition(pt);
dot->setContact(0.);
}
C.watch(true);
pts.reshape(-1, 2);
return pts;
}
arr randomPts(const uint n = 20, const double lb = -0.1,
const double ub = 0.1) {
arr pts;
for (uint i = 0; i < n; ++i) {
arr pt(2);
rndUniform(pt, lb, ub);
pts.append(pt);
}
pts.reshape(-1, 2);
return pts;
}
std::map<uint, arr> randomPtsMulti(const uint n1 = 20, const uint n2 = 20) {
std::map<uint, arr> res;
res[0] = randomPts(n1, -0.07, 0.05);
res[1] = randomPts(n2, -0.05, 0.07);
return res;
}
arr LISlogo(bool large=false) {
arr pts;
pts << FILE("./in/lis.txt");
if(!large){
pts = pts / 10000.;
}
// pts = pts + 0.25;
if (large){
pts = pts / 2500.;
for (uint i=0; i<pts.d0; ++i){
pts(i, 0) += 0.15;
pts(i, 1) -= 0.1;
}
}
pts.reshape(-1, 2);
return pts;
}
std::map<uint, arr> LISlogoMulti() {
arr pts1;
pts1 << FILE("./in/lis_multi_1.txt");
arr pts2;
pts2 << FILE("./in/lis_multi_2.txt");
pts1 = pts1 / 4000.;
pts2 = pts2 / 4000.;
double x = 0.15;
double y = -0.1;
for (uint i = 0; i < pts1.d0; ++i) {
pts1(i, 0) += x;
pts1(i, 1) += y;
}
for (uint i = 0; i < pts2.d0; ++i) {
pts2(i, 0) += x;
pts2(i, 1) += y;
}
pts1.reshape(-1, 2);
pts2.reshape(-1, 2);
std::map<uint, arr> res;
res[0] = pts1;
res[1] = pts2;
return res;
}