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

31 lines
811 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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