i'm looking model population curves using interpolative spline between 7 control points. problem can't find grokkable/digestable coding/math resource compares pros , cons of various splines in layman's terms.
first, here's simplified illustration of population curve in code:
struct curvepoint { public: short height; // point's height along population curve, measured age in years (can negative, representing building trend peak/valley happen in future) double width; // (nonnegative) width of population curve @ point, measured number of people **born within single year** // each curvepoint represents 1 "bar" of population pyramid that's 1 year tall. }; class populationcurve { public: std::array<curvepoint, 7> control_points; // assumes control_points[i].height < control_points[i + 1].height , control_points[i].width >= 0 // control_points[0] young end of curve (typically nonpositive number; see above) // control_points[6] old end of curve (typically representing longevity of population; if so, control_points[6].width 0 since no 1 left alive @ point) std::vector<curvepoint> constructcurve() { std::vector<curvepoint> curve; short youngest_age = control_points[0].height; short oldest_age = control_points[6].height; (auto = youngest_age; <= oldest_age; ++a) { curvepoint p; p.height = a; // p.width = ??? (the interpolated width @ age a) curve.push_back(p); } return curve; } void deconstructcurve(std::vector<curvepoint> curve) { std::array<curvepoint, 7> sampled_control_points; // ??? (turn point samples input curve control points appropriate) control_points = sampled_control_points; } };
the hardcoding of 7 control points intentional. i'm implementing choice between 2 compression schemes: virtually lossless compression of 7 control points in 44 bytes, , lossy compression of 7 control points in 20 bytes (my application more memory/disk-limited cpu-limited). don't believe compression schemes relevant question, let me know if need show code, if there's reason should considering <7 or >7 control points.
here criteria i'm looking in spline, in descending order of importance:
- interpolation between control points. far important criterion; otherwise, would've used bézier curve or b-spline.
- interpolation between first , last control point only. if points aren't interpolated between, first , last can (i.e. bézier curve or b-spline would've got me).
- fast constructability + deconstructability. there's near-1:1 correlation between
constructcurve()
,deconstructcurve()
; every call construct followed call deconstruct, i'm interested in combined performance , not performance of either 1 individually. being said, while i'm interested in memory/disk optimization right now, not going prematurely optimize speed, consideration only. - reasonably accurate deconstructability.
- lossless deconstructability if no changes curve made. i.e. if
deconstructcurve(constructcurve());
called,control_points
remain same. - prettiness =) (since linear interpolation between control points is best match rest of criteria...)
i didn't post question on math since it's not entirely language-agnostic , contains c++ code. didn't post on gamedev since it's question of implementation , not design.