当前位置: 首页 > news >正文

C++:三次B样条插值

发现的一个可以实现三次B样条的库,可以更加专注于项目的代码实现,提高编程效率。

#include <iostream>
#include <vector>
#include <boost/math/interpolators/cubic_b_spline.hpp>

int main() {
    // 给定控制点
    std::vector<double> x = {1, 2, 3, 4, 5, 6, 7};
    std::vector<double> y = {1, 2, 3, 4, 5, 6, 7};

    // 创建三次B样条插值器
    double t0 = 0;  // 起始参数
    double dt = 1;  // 步长
    auto x_interpolator = boost::math::cubic_b_spline<double>(x.begin(), x.end(), t0, dt);
    auto y_interpolator = boost::math::cubic_b_spline<double>(y.begin(), y.end(), t0, dt);

    // 生成100个插值点
    int num_points = 100;
    std::vector<std::pair<double, double>> interpolated_points;
    for (int i = 0; i < num_points; ++i) {
        // 均匀取值
        double t = t0 + i * (static_cast<double>(x.size()-1) / (num_points - 1));
        double interpolated_x = x_interpolator(t);
        double interpolated_y = y_interpolator(t);
        interpolated_points.emplace_back(interpolated_x, interpolated_y);
    }
    
    // 输出插值点
    for (const auto& point : interpolated_points) {
        std::cout << "(" << point.first << ", " << point.second << ")\n";
    }
    return 0;
}

相关文章:

  • C++ 模版
  • Unity 创建签名证书、获取签名证书信息,证书指纹
  • k8s 修改节点驱逐阈值
  • 基础知识《HTTP字段与状态码详细说明》
  • CP210x 驱动秘籍:打通 Windows 11 端口的任督二脉
  • ssh转发笔记
  • 自然语言秒转SQL—— 免费体验 OB Cloud Text2SQL 数据查询
  • Java开发之微服务架构设计:Spring Cloud Alibaba核心组
  • 结构型模式之代理模式:控制访问的智能方式
  • 通过 CSS 的 命名页面(Named Pages) 技术实现作用域隔离,实现 @page 样式仅影响当前组件
  • Java 中 getCanonicalName、getSimpleName、getName、getTypeName 的区别
  • leetcode刷题-动态规划12
  • (链表)206. 反转链表
  • Winfrom基础知识41-60
  • GolangTCP通信解决粘包问题
  • TOSUN同星TsMaster使用入门——3、使用系统变量及c小程序结合panel面板发送报文
  • Nping- Nmap中的一个工具-用于生成网络数据包并分析响应
  • 跳跃游戏 (leetcode 55
  • u8g2原理解析
  • Java中Math.random()的用法
  • 新华每日电讯:博物馆正以可亲可近替代“高冷范儿”
  • 哈马斯与以色列在多哈举行新一轮加沙停火谈判
  • 知名中医讲师邵学军逝世,终年51岁
  • 《风林火山》千呼万唤始出来,戛纳首映后口碑崩盘?
  • 国际金价下跌,中概股多数上涨,穆迪下调美国主权信用评级
  • 上海比常年平均时间提前12天入夏,明天最高气温可达33℃