Catmull-Romスプライン; Catmull-Rom Spline
概要
Catmull-Romスプラインは制御点とその近傍2点から傾きを算出する3次スプラインの一つである。
ある区間が大きく上昇または下降したとき、その近傍の区間が反動を受けるオーバーシュートと呼ばれる現象が起きやすく、扱いづらい。
スプライン補間構成
・スプライン基本クラス
・3次スプライン基本クラス
・制御点とその近傍2点から傾きを算出する3次スプライン基本クラス
・単調スプライン
・Catmull-Romスプライン
・制御点とその近傍4点から傾きを算出する3次スプライン基本クラス
・秋間スプライン
・終端タイプ列挙型
・多次元スプライン補間ジェネリッククラス
ソースコード
namespace SplineInterpolation {
/// <summary>Catmull-Romスプライン</summary>
public class CatmullRomSpline : CubicSplineNeighbor2 {
/// <summary>コンストラクタ</summary>
public CatmullRomSpline(EndType type = EndType.Open) : base(type) {
}
/// <summary>制御点における傾き</summary>
protected override double Grad(double vm1, double v0, double vp1) {
return (-vm1 + vp1) / 2;
}
}
}
実行例
Spline sp1 = new CatmullRomSpline(EndType.Open);
sp1.Set(12, 15, 15, 10, 10, 10, 10.5, 15, 50, 60, 85);
using(StreamWriter stream = new StreamWriter("plot_catmullrom.txt")) {
stream.WriteLine("x,y");
for(decimal x = -1.0m; x <= sp1.Points; x += 0.01m) {
stream.WriteLine($"{x},{sp1.Value((double)x)}");
}
}
Spline sp2 = new CatmullRomSpline(EndType.Close);
sp2.Set(12, 15, 30, 30, 20, 10, 20, 20, 50, 20, 25);
using(StreamWriter stream = new StreamWriter("plot_catmullrom_close.txt")) {
stream.WriteLine("x,y");
for(decimal x = -5.0m; x <= sp2.Points + 4; x += 0.01m) {
stream.WriteLine($"{x},{sp2.Value((double)x)}");
}
}
var sp3 = new SplineMultiDimension<CatmullRomSpline>(2, EndType.Close);
sp3.Set(new Vector(-1, -1), new Vector(-2, 0), new Vector(-1, +1), new Vector(+1, -1), new Vector(+2, 0), new Vector(+1, +1));
using(StreamWriter stream = new StreamWriter("plot_catmullrom_parametric.txt")) {
stream.WriteLine("x,y");
for(decimal t = 0; t <= sp3.Points; t += 0.01m) {
var v = sp3.Value((double)t);
stream.WriteLine(v);
}
}
関連項目
3次スプライン補間基本クラス
3次スプライン補間基本クラス 単体テスト
単調スプライン
Catmull-Romスプライン