solve-bezier-one-d.cpp revision c8589a6c7367d09fa756755cef0dd448c7328a71
#include <cmath>
#include <algorithm>
//#include <valarray>
/*** Find the zeros of the bernstein function. The code subdivides until it is happy with the
* linearity of the function. This requires an O(degree^2) subdivision for each step, even when
* there is only one solution.
*/
namespace Geom{
template<class t>
//const unsigned MAXDEPTH = 23; // Maximum depth for recursion. Using floats means 23 bits precision max
//const double BEPSILON = ldexp(1.0,(-MAXDEPTH-1)); /*Flatness control value */
//const double SECANT_EPSILON = 1e-13; // secant method converges much faster, get a bit more precision
/**
* This function is called _a lot_. We have included various manual memory management stuff to reduce the amount of mallocing that goes on. In the future it is possible that this will hurt performance.
**/
class Bernsteins{
public:
//std::vector<double> bc;
{
}
void subdivide(double const *V,
double t,
double *Left,
double *Right);
unsigned
control_poly_flat_enough(double const *V);
double horner(const double *b, double t);
void
find_bernstein_roots(double const *w, /* The control points */
unsigned depth, /* The depth of the recursion */
};
/*
* find_bernstein_roots : Given an equation in Bernstein-Bernstein form, find all
* of the roots in the open interval (0, 1). Return the number of roots found.
*/
void
find_bernstein_roots(double const *w, /* The control points */
unsigned degree, /* The degree of the polynomial */
unsigned depth, /* The depth of the recursion */
{
}
void
{
double* w = &(bzl[0]);
}
unsigned depth, /* The depth of the recursion */
double left_t,
double right_t)
{
size_t n_crossings = 0;
//std::cout << "w[0] = " << w[0] << std::endl;
for (size_t i = 1; i < N; i++)
{
//std::cout << "w[" << i << "] = " << w[i] << std::endl;
if (sign != 0)
{
{
++n_crossings;
}
}
}
//std::cout << "n_crossings = " << n_crossings << std::endl;
if (n_crossings == 0) return; // no solutions here
{
//std::cout << "depth = " << depth << std::endl;
/* Stop recursion when the tree is deep enough */
/* if deep enough, return 1 solution at midpoint */
{
//printf("bottom out %d\n", depth);
return;
}
double s = 0, t = 1;
double e = 1e-10;
int side = 0;
for (size_t n = 0; n < 100; ++n)
{
{
side = -1;
}
{
side = +1;
}
else break;
}
return;
}
/* Otherwise, solve recursively after subdividing control polygon */
// double Left[N], /* New left and right */
// Right[N]; /* control polygons */
//const double t = 0.5;
double* LR = new double[2*N];
for (size_t i = 1; i < N; ++i)
{
for (size_t j = 0; j < N-i; ++j)
{
}
}
/* Solution is exactly on the subdivision point. */
if (Right[0] == 0)
{
}
delete[] LR;
}
// suggested by Sederberg.
double Bernsteins::horner(const double *b, double t)
{
u = 1.0 - t;
tn = 1.0;
tmp = b[0] * u;
{
tn *= t;
}
}
#if 0
/*
* control_poly_flat_enough :
* Check if the control polygon of a Bernstein curve is flat enough
* for recursive subdivision to bottom out.
*
*/
unsigned
Bernsteins::control_poly_flat_enough(double const *V)
{
/* Find the perpendicular distance from each interior control point to line connecting V[0] and
* V[degree] */
/* Derive the implicit equation for line connecting first */
/* and last control points */
const double a = V[0] - V[degree];
double max_distance_above = 0.0;
double max_distance_below = 0.0;
for (unsigned i = 1; i < degree; i++) {
/* Compute distance from each of the points to that line */
const double d = (a + V[i]) * ii - a;
double dist = d*d;
// Find the largest distance
if (d < 0.0)
else
}
/* Compute bounding interval*/
//printf("error %g %g %g\n", error, a, BEPSILON * a);
}
#endif
};
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :