样条选项用于在总体曲线上的控制点之间进行插值?

时间:2016-06-06 20:46:11

标签: c++ interpolation spline

我希望使用7个控制点之间的插值样条来对人口曲线进行建模。我的问题是我找不到任何grokkable / digestable编码/数学资源来比较外行人的各种样条的利弊。

首先,这是我的代码中人口曲线的简化说明:

struct CurvePoint {
public:
    short height; // the point's height along a population curve, measured as age in years (can be negative, representing a building trend whose peak/valley will happen in the future)
    double width; // the (nonnegative) width of the population curve at this point, measured as number of people **born within a single year**
    // Each CurvePoint represents one "bar" of a population pyramid that's one year tall.
};

class PopulationCurve {
public:
    std::array<CurvePoint, 7> control_points; // assumes that control_points[i].height < control_points[i + 1].height and that control_points[i].width >= 0
    // control_points[0] is the young end of the curve (typically a nonpositive number; see above)
    // control_points[6] is the old end of the curve (typically representing the longevity of the population; if so, control_points[6].width will be 0 since no one is left alive at that point)

    std::vector<CurvePoint> constructCurve() {
        std::vector<CurvePoint> curve;
        short youngest_age = control_points[0].height;
        short oldest_age = control_points[6].height;
        for (auto a = youngest_age; a <= oldest_age; ++a) {
            CurvePoint p;
            p.height = a;
            // p.width = ??? (the interpolated width at age a)
            curve.push_back(p);
        }
        return curve;
    }
    void deconstructCurve(std::vector<CurvePoint> curve) {
        std::array<CurvePoint, 7> sampled_control_points;
        // ??? (turn point samples from the input curve into control points as appropriate)
        control_points = sampled_control_points;
    }
};

7个控制点的硬编码是故意的。我正在实现两种压缩方案之间的选择:44个字节中的7个控制点的无损压缩,以及20个字节中7个控制点的有损压缩(我的应用程序目前比CPU限制更多的内存/磁盘限制)。我不相信这些压缩方案与问题相关,但是如果我需要显示他们的代码,请告诉我,特别是如果有充分的理由我应该考虑&lt; 7或&gt; 7控制点。

以下是我在样条曲线中寻找的标准,按重要性降序排列

  1. 所有控制点之间的插值。这是迄今为止最重要的标准;否则,我会使用Bézier曲线或b样条曲线。
  2. 第一个和最后一个控制点之间的插值。如果所有点都没有在它们之间进行插值,那么只有第一个和最后一个点可以是(即Bézier曲线或b样条会得到什么)。
  3. 快速可施工性+解构性。 constructCurve()deconstructCurve()之间存在近1:1的相关性;几乎每一个构造的调用最终都会被调用解构,所以我只对单独的表现和其中任何一个的表现感兴趣。话虽如此,虽然我现在对内存/磁盘优化非常感兴趣,但我不会过早地优化速度,所以这只是一个考虑因素。
  4. 合理准确的解构性。
  5. 如果曲线没有变化,则无损解构。即如果调用deconstructCurve(constructCurve());control_points将保持不变。
  6. Prettiness =)(因为控制点之间的线性插值是其余标准的最佳匹配...)
  7. 我没有在数学上发布这个问题,因为它不完全与语言无关并且包含C ++代码。我没有在gamedev上发布它,因为它是一个实现问题,而不是设计。

0 个答案:

没有答案
相关问题