solve-bezier.cpp revision 6553067c3efe2755cef7c7dde1e3623ebfcabbab
2035N/A/*** Find the zeros of a Bezier. The code subdivides until it is happy with the linearity of the 2035N/A * function. This requires an O(degree^2) subdivision for each step, even when there is only one 2035N/A * We try fairly hard to correctly handle multiple roots. 2035N/A//#define debug(x) do{x;}while(0) 2035N/Astatic int SGN(t x) {
return (x > 0 ?
1 : (x < 0 ? -
1 : 0)); }
2035N/A //std::vector<double> dsolutions; 2035N/A for (
unsigned i = 0; i < N; i++)
2035N/A for (
unsigned i =
1; i < N; i++) {
2035N/A for (
unsigned j = 0; j < N - i; j++) {
//convex_hull_marching(bz, bz, solutions, left_t, right_t); //A constant bezier, even if identically zero, has no roots double d =
bz[0] -
bz[
1];
//std::cout << "initial = " << bz << std::endl; //std::cout << solutions << std::endl; //std::cout << "w[0] = " << bz[0] << std::endl; //std::cout << "w[" << i << "] = " << w[i] << std::endl; //std::cout << "n_crossings = " << n_crossings << std::endl; //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); /* Otherwise, solve recursively after subdividing control polygon */ // If subdivision is working poorly, split around the leftmost root of the derivative // split at midpoint, because it is cheap debug(
std::
cout <<
"Solution is exactly on the subdivision point.\n");
// suggested by Sederberg. for (
size_t n = 0; n <
100; ++n)
<<
", accepting solution " << r
<<
"after " << n <<
"iterations\n");
c-file-style:"stroustrup" c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :