C# 클래스 SimShift.Map.Splines.CubicSpline

Cubic spline interpolation. Call Fit (or use the corrector constructor) to compute spline coefficients, then Eval to evaluate the spline at other X coordinates.

This is implemented based on the wikipedia article: http://en.wikipedia.org/wiki/Spline_interpolation I'm not sure I have the right to include a copy of the article so the equation numbers referenced in comments will end up being wrong at some point.

This is not optimized, and is not MT safe. This can extrapolate off the ends of the splines. You must provide points in X sort order.

파일 보기 프로젝트 열기: nlhans/SimShift 1 사용 예제들

공개 메소드들

메소드 설명
Compute ( float x, float y, float xs, float startSlope = float.NaN, float endSlope = float.NaN, bool debug = false ) : float[]

Static all-in-one method to fit the splines and evaluate at X coordinates.

CubicSpline ( ) : System

Default ctor.

CubicSpline ( float x, float y, float startSlope = float.NaN, float endSlope = float.NaN, bool debug = false ) : System

Construct and call Fit.

Eval ( float x, bool debug = false ) : float[]

Evaluate the spline at the specified x coordinates. This can extrapolate off the ends of the splines. You must provide X's in ascending order. The spline must already be computed before calling this, meaning you must have already called Fit() or FitAndEval().

EvalSlope ( float x, bool debug = false ) : float[]

Evaluate (compute) the slope of the spline at the specified x coordinates. This can extrapolate off the ends of the splines. You must provide X's in ascending order. The spline must already be computed before calling this, meaning you must have already called Fit() or FitAndEval().

Fit ( float x, float y, float startSlope = float.NaN, float endSlope = float.NaN, bool debug = false ) : void

Compute spline coefficients for the specified x,y points. This does the "natural spline" style for ends. This can extrapolate off the ends of the splines. You must provide points in X sort order.

FitAndEval ( float x, float y, float xs, float startSlope = float.NaN, float endSlope = float.NaN, bool debug = false ) : float[]

Fit x,y and then eval at points xs and return the corresponding y's. This does the "natural spline" style for ends. This can extrapolate off the ends of the splines. You must provide points in X sort order.

FitGeometric ( float x, float y, float directions, int nOutputPoints, float &xs, float &ys ) : void

Fit the input x,y points using a 'geometric' strategy so that y does not have to be a single-valued function of x.

비공개 메소드들

메소드 설명
CheckAlreadyFitted ( ) : void

Throws if Fit has not been called.

EvalSpline ( float x, int j, bool debug = false ) : float

Evaluate the specified x value using the specified spline.

GetNextXIndex ( float x ) : int

Find where in xOrig the specified x falls, by simultaneous traverse. This allows xs to be less than x[0] and/or greater than x[n-1]. So allows extrapolation. This keeps state, so requires that x be sorted and xs called in ascending order, and is not multi-thread safe.

메소드 상세

Compute() 공개 정적인 메소드

Static all-in-one method to fit the splines and evaluate at X coordinates.
public static Compute ( float x, float y, float xs, float startSlope = float.NaN, float endSlope = float.NaN, bool debug = false ) : float[]
x float Input. X coordinates to fit.
y float Input. Y coordinates to fit.
xs float Input. X coordinates to evaluate the fitted curve at.
startSlope float Optional slope constraint for the first point. Single.NaN means no constraint.
endSlope float Optional slope constraint for the final point. Single.NaN means no constraint.
debug bool Turn on console output. Default is false.
리턴 float[]

CubicSpline() 공개 메소드

Default ctor.
public CubicSpline ( ) : System
리턴 System

CubicSpline() 공개 메소드

Construct and call Fit.
public CubicSpline ( float x, float y, float startSlope = float.NaN, float endSlope = float.NaN, bool debug = false ) : System
x float Input. X coordinates to fit.
y float Input. Y coordinates to fit.
startSlope float Optional slope constraint for the first point. Single.NaN means no constraint.
endSlope float Optional slope constraint for the final point. Single.NaN means no constraint.
debug bool Turn on console output. Default is false.
리턴 System

Eval() 공개 메소드

Evaluate the spline at the specified x coordinates. This can extrapolate off the ends of the splines. You must provide X's in ascending order. The spline must already be computed before calling this, meaning you must have already called Fit() or FitAndEval().
public Eval ( float x, bool debug = false ) : float[]
x float Input. X coordinates to evaluate the fitted curve at.
debug bool Turn on console output. Default is false.
리턴 float[]

EvalSlope() 공개 메소드

Evaluate (compute) the slope of the spline at the specified x coordinates. This can extrapolate off the ends of the splines. You must provide X's in ascending order. The spline must already be computed before calling this, meaning you must have already called Fit() or FitAndEval().
public EvalSlope ( float x, bool debug = false ) : float[]
x float Input. X coordinates to evaluate the fitted curve at.
debug bool Turn on console output. Default is false.
리턴 float[]

Fit() 공개 메소드

Compute spline coefficients for the specified x,y points. This does the "natural spline" style for ends. This can extrapolate off the ends of the splines. You must provide points in X sort order.
public Fit ( float x, float y, float startSlope = float.NaN, float endSlope = float.NaN, bool debug = false ) : void
x float Input. X coordinates to fit.
y float Input. Y coordinates to fit.
startSlope float Optional slope constraint for the first point. Single.NaN means no constraint.
endSlope float Optional slope constraint for the final point. Single.NaN means no constraint.
debug bool Turn on console output. Default is false.
리턴 void

FitAndEval() 공개 메소드

Fit x,y and then eval at points xs and return the corresponding y's. This does the "natural spline" style for ends. This can extrapolate off the ends of the splines. You must provide points in X sort order.
public FitAndEval ( float x, float y, float xs, float startSlope = float.NaN, float endSlope = float.NaN, bool debug = false ) : float[]
x float Input. X coordinates to fit.
y float Input. Y coordinates to fit.
xs float Input. X coordinates to evaluate the fitted curve at.
startSlope float Optional slope constraint for the first point. Single.NaN means no constraint.
endSlope float Optional slope constraint for the final point. Single.NaN means no constraint.
debug bool Turn on console output. Default is false.
리턴 float[]

FitGeometric() 공개 정적인 메소드

Fit the input x,y points using a 'geometric' strategy so that y does not have to be a single-valued function of x.
public static FitGeometric ( float x, float y, float directions, int nOutputPoints, float &xs, float &ys ) : void
x float Input x coordinates.
y float Input y coordinates, do not need to be a single-valued function of x.
directions float
nOutputPoints int How many output points to create.
xs float Output (interpolated) x values.
ys float Output (interpolated) y values.
리턴 void