53 static double a[33] = {
54 1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0
68 a[ntop] = a[j1] * ntop;
75 double Ni(
int n,
int i) {
81 double Basis(
int n,
int i,
double t) {
83 const double ti = (i == 0) ? 1.0 : pow(t, i);
84 const double tni = (n == i) ? 1.0 : pow(1 - t, n - i);
85 return Ni(n, i) * ti * tni;
90 bezier(
int npts,
double b[],
int cpts,
double p[]) {
97 const double step = (double) 1.0 / (cpts - 1);
105 for (i1 = 1; i1 <= cpts; i1++) {
107 if ((1.0 - t) < 5e-6) {
111 for (j = 1; j <= 3; j++) {
114 for (i = 1; i <= npts; i++) {
115 p[icount + j] = p[icount + j] +
Basis(npts - 1, i - 1, t) * b[jcount];
129 double* def =
new double[1 + (int)init.size() * 3];
130 for (
int i = 0; i < (int)init.size(); ++i) {
132 def[i * 3 + 1] = init[i].x();
133 def[i * 3 + 2] = init[i].z();
134 def[i * 3 + 3] = init[i].y();
136 double* ret_buf =
new double[numPoints * 3 + 1];
137 bezier((
int)init.size(), def, numPoints, ret_buf);
140 for (
int i = 0; i < (int)numPoints; i++) {
141 Position current(ret_buf[i * 3 + 1], ret_buf[i * 3 + 3], ret_buf[i * 3 + 2]);
142 if (prev != current && !
ISNAN(current.
x()) && !
ISNAN(current.
y()) && !
ISNAN(current.
z())) {
143 ret.push_back(current);
double z() const
Returns the z-position.
double y() const
Returns the y-position.
double x() const
Returns the x-position.
double Basis(int n, int i, double t)
A point in 2D or 3D with translation and scaling methods.
void bezier(int npts, double b[], int cpts, double p[])