59 static double a[33] = {
60 1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0
74 a[ntop] = a[j1] * ntop;
81 double Ni(
int n,
int i) {
87 double Basis(
int n,
int i,
double t) {
89 const double ti = (i == 0) ? 1.0 : pow(t, i);
90 const double tni = (n == i) ? 1.0 : pow(1 - t, n - i);
91 return Ni(n, i) * ti * tni;
96 bezier(
int npts,
double b[],
int cpts,
double p[]) {
103 const double step = (double) 1.0 / (cpts - 1);
111 for (i1 = 1; i1 <= cpts; i1++) {
113 if ((1.0 - t) < 5e-6) {
117 for (j = 1; j <= 3; j++) {
120 for (i = 1; i <= npts; i++) {
121 p[icount + j] = p[icount + j] +
Basis(npts - 1, i - 1, t) * b[jcount];
135 double* def =
new double[1 + (int)init.size() * 3];
136 for (
int i = 0; i < (int)init.size(); ++i) {
138 def[i * 3 + 1] = init[i].x();
139 def[i * 3 + 2] = init[i].z();
140 def[i * 3 + 3] = init[i].y();
142 double* ret_buf =
new double[numPoints * 3 + 1];
143 bezier((
int)init.size(), def, numPoints, ret_buf);
146 for (
int i = 0; i < (int)numPoints; i++) {
147 Position current(ret_buf[i * 3 + 1], ret_buf[i * 3 + 3], ret_buf[i * 3 + 2]);
148 if (prev != current && !
ISNAN(current.
x()) && !
ISNAN(current.
y()) && !
ISNAN(current.
z())) {
149 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[])