我希望使用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控制点。
以下是我在样条曲线中寻找的标准,按重要性降序排列:
constructCurve()
和deconstructCurve()
之间存在近1:1的相关性;几乎每一个构造的调用最终都会被调用解构,所以我只对单独的表现和其中任何一个的表现感兴趣。话虽如此,虽然我现在对内存/磁盘优化非常感兴趣,但我不会过早地优化速度,所以这只是一个考虑因素。deconstructCurve(constructCurve());
,control_points
将保持不变。我没有在数学上发布这个问题,因为它不完全与语言无关并且包含C ++代码。我没有在gamedev上发布它,因为它是一个实现问题,而不是设计。