18namespace layer1_foundations {
41 double desired_distance,
43 int (*compute_point_function)(
double t,
double *pt,
void *extra_data,
int verbose_level),
49 int f_v = (verbose_level >= 1);
50 double t, d, dt, t_last, tf;
55 double epsilon = 0.0001;
58 cout <<
"parametric_curve::init" << endl;
68 cout <<
"parametric_curve::init nb_dimensions=" <<
nb_dimensions << endl;
69 cout <<
"parametric_curve::init desired_distance=" <<
desired_distance << endl;
70 cout <<
"parametric_curve::init boundary=" <<
boundary << endl;
71 cout <<
"parametric_curve::init t0=" <<
t0 << endl;
72 cout <<
"parametric_curve::init t1=" <<
t1 << endl;
73 cout <<
"parametric_curve::init N=" << N << endl;
77 cout <<
"parametric_curve::init dt=" << dt << endl;
81 cout <<
"parametric_curve::init nb_dimensions != 2" << endl;
92 cout <<
"parametric_curve::init computing value at t=" << setw(8) << t << endl;
94 f_is_valid = (*compute_point_function)(t, coords,
extra_data, verbose_level);
96 cout <<
"parametric_curve::init computing value at t=" << setw(8) << t <<
" done" << endl;
101 cout <<
"created point t=" << setw(8) << t <<
" = (" << coords[0] <<
"," << coords[1] <<
")" << endl;
107 cout <<
"invalid starting point" << endl;
113 cout <<
"parametric_curve::init d > boundary, performing a search for the starting value of t" << endl;
114 cout <<
"d=" << d << endl;
115 cout <<
"boundary=" <<
boundary << endl;
118 double epsilon = 0.0001;
125 cout <<
"parametric_curve::init computing value at tr=" << setw(8) << tr << endl;
127 f_is_valid = (*compute_point_function)(tr, coords,
extra_data, 0 );
129 cout <<
"parametric_curve::init computing value at tr=" << setw(8) << tr <<
" done" << endl;
143 cout <<
"performing a search for the starting value of t in the interval tl=" << tl <<
", tr=" << tr << endl;
146 while (
ABS(tr - tl) > epsilon) {
147 tm = (tl + tr) * 0.5;
151 cout <<
"parametric_curve::init computing value at tm=" << setw(8) << tm << endl;
153 f_is_valid = (*compute_point_function)(tm, coords,
extra_data, 0 );
155 cout <<
"parametric_curve::init computing value at tm=" << setw(8) << tm <<
" done" << endl;
173 cout <<
"created starting value t=" << setw(8) << t << endl;
178 cout <<
"parametric_curve::init computing value at t=" << setw(8) << t << endl;
180 f_is_valid = (*compute_point_function)(t, coords,
extra_data, 0 );
182 cout <<
"parametric_curve::init computing value at t=" << setw(8) << t <<
" done" << endl;
189 cout <<
"the initial point is invalid" << endl;
194 cout <<
"created point t=" << setw(8) << t <<
" = (" << coords[0] <<
"," << coords[1] <<
")" << endl;
199 vector<parametric_curve_point> Future;
204 cout <<
"adding point " <<
Pts.size() << endl;
216 cout <<
"t_last = " << setw(8) << t_last <<
" Future.size() = " << Future.size() << endl;
220 while (Future.size()) {
221 if (!Future[Future.size() - 1].f_is_valid) {
224 tf = Future[Future.size() - 1].t;
227 t = (t_last + tf) * 0.5;
229 cout <<
"t_last = " << setw(8) << t_last <<
" t = " << setw(8) << t <<
" tf=" << setw(8) << tf << endl;
233 cout <<
"t_last = " << setw(8) << t_last <<
" tf = " << setw(8) << tf <<
" t = " << setw(8) << t <<
" popped from Future" << endl;
240 cout <<
"no success, moving on by dt, clearing Future" << endl;
243 while (Future.size()) {
247 cout <<
"t_last = " << setw(8) << t_last <<
" t = " << setw(8) << t << endl;
256 if (
ABS(t_last - t) < epsilon) {
257 cout <<
"t_last == t" << endl;
258 cout <<
"t_last = " << setw(8) << t_last << endl;
259 cout <<
"adding dt" << endl;
264 if (
ABS(t - t_last) < epsilon) {
266 cout <<
"no success, ABS(t - t_last) < epsilon, ABS(t - t_last)=" <<
ABS(t - t_last) << endl;
272 cout <<
"t_last = " << setw(8) << t_last <<
" t = " << setw(8) << t << endl;
273 cout <<
"t = " << setw(8) << t <<
" t1 = " <<
t1 << endl;
274 cout <<
"t - t_last = " << setw(8) << t - t_last << endl;
278 cout <<
"t > t1, break" << endl;
284 cout <<
"parametric_curve::init computing value at t=" << setw(8) << t << endl;
286 f_is_valid = (*compute_point_function)(t, coords,
extra_data, 0 );
288 cout <<
"parametric_curve::init computing value at t=" << setw(8) << t <<
" done" << endl;
295 coords0[h] =
Pts[
Pts.size() - 1].coords[h];
298 cout <<
"t_last = " << setw(8) << t_last <<
" : (" << coords0[0] <<
"," << coords0[1] <<
")" << endl;
302 cout <<
"t = " << setw(8) << t <<
" d = " << d << endl;
309 cout <<
"t=" << setw(8) << t <<
" d > desired_distance, pushing to Future, moving back to t_last" << setw(8) << t_last << endl;
316 cout <<
"top element of Future stack is t=" << setw(8) << Future[Future.size() - 1].t <<
" we are pushing " << t << endl;
318 Future.push_back(Pt);
323 if ((
int) Future.size() > N) {
325 cout <<
"Future.size() > N, popping stack" << endl;
328 while (Future.size() > 0) {
331 cout <<
"after popping stack, Future.size() = " << Future.size() <<
", t = " << setw(8) << t << endl;
340 cout <<
"t=" << setw(8) << t <<
" d < desired_distance, valid point" << endl;
346 cout <<
"created point t=" << setw(8) << t <<
" = (" << coords[0] <<
"," << coords[1] <<
") with distance from origin " << d << endl;
355 cout <<
"adding point " <<
Pts.size() << endl;
362 coords0[h] =
Pts[
Pts.size() - 1].coords[h];
364 cout <<
"created point " << coords0[0] <<
"," << coords0[1] << endl;
367 cout <<
"skipping" << endl;
373 coords0[h] = Future[Future.size() - 1].coords[h];
388 cout <<
"parametric_curve::init done" << endl;
an individual point on a continuous curve, sampled through parametric_curve
void init(double t, int f_is_valid, double *x, int nb_dimensions, int verbose_level)
void init(int nb_dimensions, double desired_distance, double t0, double t1, int(*compute_point_function)(double t, double *pt, void *extra_data, int verbose_level), void *extra_data, double boundary, int N, int verbose_level)
int(* compute_point_function)(double t, double *pt, void *extra_data, int verbose_level)
std::vector< parametric_curve_point > Pts
numerical functions, mostly concerned with double
double distance_euclidean(double *x, double *y, int len)
double distance_from_origin(double x1, double x2, double x3)
the orbiter library for the classification of combinatorial objects