#include "bessel.h" vector Bessel::run(const vector &points, double step) { vector res; for (float t = 0; t <= 1; t += step) { Point p = bezier_curve(points, t); res.push_back(p); } return res; } // 计算n次贝塞尔曲线上的点 Point Bessel::bezier_curve(const vector &points, double t) { int n = points.size() - 1; Point res; for (int i = 0; i <= n; ++i) { double b = binomial(n, i)* pow(t, i) * pow(1 - t, n - i); res.x = res.x + points[i].x * b; res.y = res.y + points[i].y * b; res.z = res.z + points[i].z * b; } return res; } // 计算组合数 int Bessel::binomial(int n, int i) { int res = 1; for (int j = 1; j <= i; ++j) { res *= (n - j + 1) / (double)j; //(double)十分关键,不然j=i=n时,j为分数=0; } return res; }