You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
884 B

1 year ago
#include "bessel.h"
vector<Point> Bessel::run(const vector<Point> &points, double step) {
vector<Point> 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<Point> &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;
}