cmvr-es/include/utils/base/abstract_interpolation.h

31 lines
811 B
C
Raw Normal View History

2025-08-28 10:50:22 +08:00
#ifndef INTERPOLATION_BASE_H
#define INTERPOLATION_BASE_H
#include <vector>
#include <stdexcept>
// 插值基类
class AbstractInterpolation {
protected:
std::vector<double> x_points; // 已知点的x坐标
std::vector<double> y_points; // 已知点的y坐标
// 查找x所在的区间索引二分查找
int findInterval(double x) const;
public:
// 构造函数
AbstractInterpolation(const std::vector<double>& x, const std::vector<double>& y);
// 析构函数
virtual ~AbstractInterpolation() = default;
// 纯虚函数:单个点插值
virtual double interpolate(double x) const = 0;
// 批量插值(默认实现)
virtual std::vector<double> interpolate(const std::vector<double>& x_values) const;
};
#endif // INTERPOLATION_BASE_H