北京大学廉政建设研究中心网站,天津建站方案,做外贸一年能赚多少,什么软件可以做app效果可查看上一篇博文#xff1a;js手动画平滑曲线#xff0c;贝塞尔曲线拟合【代码】js手动画平滑曲线#xff0c;贝塞尔曲线拟合。https://blog.csdn.net/qiufeng_xinqing/article/details/131711963?spm1001.2014.3001.5502
代码如下#xff1a;
#include cmathjs手动画平滑曲线贝塞尔曲线拟合【代码】js手动画平滑曲线贝塞尔曲线拟合。https://blog.csdn.net/qiufeng_xinqing/article/details/131711963?spm1001.2014.3001.5502
代码如下
#include cmath
#include cstdint
#include exception
#include vectornamespace line {
// 二维坐标点定义first对应x值second对应y值
using point_t std::pairdouble, double;/// summary
/// 阶乘递归即 n! n * (n-1) * (n-2) * (n-3) * ...* 1
/// /summary
/// param namenum阶乘的数/param
/// returns阶乘结果数/returns
double factorial(double num)
{return (num 1) ? 1 : (num * factorial(num - 1));
}/// summary
/// 通过多个控制点计算当前贝塞尔曲线上的点坐标横坐标为[0,1]
/// 关于 贝塞尔曲线https://www.cnblogs.com/fangsmile/articles/11642607.html
/// /summary
/// param namepoints控制点集合/param
/// param namestepTime横轴的步长如果为零则使用默认的 0.01 使用为步长/param
/// param nameretLine贝塞尔曲线上的点坐标集/param
/// returns贝塞尔曲线上的点坐标集/returns
const std::vectorpoint_t calcBezierLine(const std::vectorpoint_t points, double stepTime, std::vectorpoint_t retLine)
{if (points.size() 2){retLine.resize(1);retLine[0] points[0];return retLine;}int32_t pointsn points.size() - 1;int64_t pointsFact factorial(pointsn);int32_t retCount 0;stepTime stepTime 0 ? 0.01 : stepTime;retLine.resize((1 / stepTime) 1);for (double xt 0; xt 1; xt stepTime){double x 0.0;double y 0.0;for (int32_t n 0; n points.size(); n){const auto p points[n];if (!n){double fact std::pow((1 - xt), pointsn - n) * std::pow(xt, n);x p.first * fact;y p.second * fact;}else{double fact pointsFact / factorial(n) / factorial((int64_t)pointsn - n)* std::pow((1 - xt), (int64_t)pointsn - n) * std::pow(xt, n);x fact * p.first;y fact * p.second;}}retLine[retCount] std::make_pair(x, y);}return retLine;
}
}int main()
{std::vectorline::point_t points({ {115, 53},{392,105},{555,62}, {681, 94} });std::vectorline::point_t retPoints(100);line::calcBezierLine(points, 0.01, retPoints);return 0;
}