solve-bezier-one-d.cpp revision 29684a16b6c92bee28a94fdc2607bcc143950fa8
#include "solver.h"
#include "point.h"
#include <algorithm>
/*** 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>
/*
* Forward declarations
*/
static void
Bernstein(double const *V,
unsigned degree,
double t,
double *Left,
double *Right);
static unsigned
control_poly_flat_enough(double const *V, unsigned degree,
/*
* 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 */
{
unsigned n_crossings = 0; /* Number of zero-crossings */
for (unsigned i = 1; i <= degree; i++) {
if (sign) {
n_crossings++;
}
}
}
switch (n_crossings) {
case 0: /* No solutions here */
return;
case 1:
/* Unique solution */
/* Stop recursion when the tree is deep enough */
/* if deep enough, return 1 solution at midpoint */
return;
}
// I thought secant method would be faster here, but it'aint. -- njh
return;
}
break;
}
/* Otherwise, solve recursively after subdividing control polygon */
const double split = 0.5;
/* Solution is exactly on the subdivision point. */
if (Right[0] == 0)
}
/*
* control_poly_flat_enough :
* Check if the control polygon of a Bernstein curve is flat enough
* for recursive subdivision to bottom out.
*
*/
static unsigned
control_poly_flat_enough(double const *V, /* Control points */
unsigned degree,
{
/* 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*b + c;
double dist = d*d;
// Find the largest distance
if (d < 0.0)
else
}
const double abSquared = (a * a) + (b * b);
/* Compute bounding interval*/
return 1;
return 0;
}
/*
* Bernstein :
* Evaluate a Bernstein function at a particular parameter value
* Fill in control points for resulting sub-curves.
*
*/
static void
Bernstein(double const *V, /* Control pts */
unsigned degree, /* Degree of bernstein curve */
double t, /* Parameter value */
double *Left, /* RETURN left half ctl pts */
double *Right) /* RETURN right half ctl pts */
{
/* Copy control points */
/* Triangle computation */
const double omt = (1-t);
for (unsigned i = 1; i <= degree; i++) {
for (unsigned j = 0; j <= degree - i; j++) {
}
}
}
};
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(substatement-open . 0))
indent-tabs-mode:nil
c-brace-offset:0
fill-column:99
End:
vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
*/