31 lines
811 B
C
31 lines
811 B
C
|
|
#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
|
|||
|
|
|