秋間スプライン; Akima Spline
概要
秋間スプライン[1]は制御点とその近傍4点から傾きを算出する3次スプラインの一つで秋間 浩 氏によって考案された。
ある区間が大きく上昇または下降したとしても、その近傍の区間が反動を受けない。なおこの反動はオーバーシュートと呼ばれる現象である。
地表面など2次元上に等間隔で得られた値を曲面補間することに向いている。
スプライン補間構成
・スプライン基本クラス
・3次スプライン基本クラス
・制御点とその近傍2点から傾きを算出する3次スプライン基本クラス
・単調スプライン
・Catmull-Romスプライン
・制御点とその近傍4点から傾きを算出する3次スプライン基本クラス
・秋間スプライン
・終端タイプ列挙型
・多次元スプライン補間ジェネリッククラス
ソースコード
namespace SplineInterpolation {
/// <summary>秋間スプライン</summary>
public class AkimaSpline : CubicSplineNeighbor4 {
/// <summary>コンストラクタ</summary>
public AkimaSpline(EndType type = EndType.Open) : base(type) {}
/// <summary>制御点における傾き</summary>
protected override double Grad(double vm2, double vm1, double v0, double vp1, double vp2) {
double mm2 = vm1 - vm2, mm1 = v0 - vm1, mp1 = vp1 - v0, mp2 = vp2 - vp1;
if(mm1 == mp1) {
return mm1;
}
if(mm2 == mm1 && mp1 == mp2) {
return 0.5 * (mm1 + mp1);
}
if(mm1 == mm2) {
return mm1;
}
if(mp1 == mp2) {
return mp1;
}
double mm = Math.Abs(mm2 - mm1);
double mp = Math.Abs(mp1 - mp2);
return (mp1 * mm + mm1 * mp) / (mm + mp);
}
}
}
実行例
Spline sp1 = new AkimaSpline(EndType.Open);
sp1.Set(12, 15, 15, 10, 10, 10, 10.5, 15, 50, 60, 85);
using(StreamWriter stream = new StreamWriter("plot_akima.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 AkimaSpline(EndType.Close);
sp2.Set(12, 15, 30, 30, 20, 10, 20, 20, 50, 20, 25);
using(StreamWriter stream = new StreamWriter("plot_akima_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<AkimaSpline>(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_akima_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);
}
}
引用文献
[1] “A New Method of Interpolation and Smooth Curve Fitting Based on Local Procedures”, Hiroshi Akima, Journal of the Association for Computing Machinery, vol.17, no.4, pp589-602, October 1970
関連項目
3次スプライン補間基本クラス
3次スプライン補間基本クラス 単体テスト
単調スプライン
Catmull-Romスプライン