26 Bernsteins(
size_t _degree, std::vector<double> &sol)
35 double left_t,
double right_t);
49 double left_t,
double right_t,
bool )
52 B.find_bernstein_roots(
w, depth, left_t, right_t);
58 double left_t,
double right_t)
62 double*
w = &(bzl[0]);
63 B.find_bernstein_roots(
w, 0, left_t, right_t);
66void Bernsteins::find_bernstein_roots(
double const *
w,
71 size_t n_crossings = 0;
75 for (
size_t i = 1; i <
N; i++)
81 if (
sign != old_sign && old_sign != 0)
89 if (n_crossings == 0)
return;
99 const double Ax = right_t - left_t;
110 double r, fs =
w[0], ft =
w[
degree];
112 for (
size_t n = 0;
n < 100; ++
n)
114 r = (fs*t - ft*s) / (fs - ft);
115 if (fabs(t-s) < e * fabs(t+s))
break;
122 if (side == -1) fs /= 2;
125 else if (fs * fr > 0)
128 if (side == +1) ft /= 2;
133 solutions.push_back(r*right_t + (1-r)*left_t);
139 double* LR =
new double[2*
N];
141 double* Right = LR +
N;
143 std::copy(
w,
w +
N, Right);
146 for (
size_t i = 1; i <
N; ++i)
148 for (
size_t j = 0; j <
N-i; ++j)
150 Right[j] = (Right[j] + Right[j+1]) * 0.5;
155 double mid_t = (left_t + right_t) * 0.5;
Cartesian point / 2D vector and related operations.
Bernstein-Bezier polynomial.
Calculation of binomial cefficients.
Polynomial in Bernstein-Bezier basis.
Various utility functions.
int sgn(const T &x)
Sign function - indicates the sign of a numeric type.
static float sign(double number)
Returns +1 for positive numbers, -1 for negative numbers, and 0 otherwise.
void find_bernstein_roots(double const *w, unsigned degree, std::vector< double > &solutions, unsigned depth, double left_t=0, double right_t=1, bool use_secant=true)
T bernstein_value_at(double t, T const *c_, unsigned n)
Compute the value of a Bernstein-Bezier polynomial.
std::vector< double > & solutions
static constexpr size_t MAX_DEPTH
Finding roots of Bernstein-Bezier polynomials.