cbspline

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2022 License: MIT Imports: 5 Imported by: 0

README

go-cbspline

Go Reference MIT License

Overview

Package cbspline implements the Cubic Spline Interpolation algorithm.

Limitation
  • Cyclic (periodic) boundary condition does not work at all :-(

Documentation

Overview

Package cbspline implements the Cubic Spline Interpolation algorithm.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidData = errors.New("invalid data")

ErrInvalidData is an error thrown when the given parameters are not appropriate and the cubic spline curve can not be determined.

Functions

This section is empty.

Types

type Boundary

type Boundary uint8

Boundary specifies the boundary condition of a cubic spline.

const (
	Natural Boundary = iota
	NotAKnot
	Clamped
	Cyclic // periodic
)

func (Boundary) String

func (b Boundary) String() string

String returns the string representation of Boundary.

type CbSpline

type CbSpline struct {
	// contains filtered or unexported fields
}

CbSpline represents a cubic spline curve.

func New

func New(t, v []float64, b Boundary) (*CbSpline, error)

New creates and returns a cubic spline. t and v are the list of data points, and each element in them represents S(t[i]) = v[i]. t and v must be exactly the same length, and t must be sorted in ascending order.

Elements of t with the same value can appear up to two times in a row, only if the corresponding v elements are also equivalent. If different v values are specified for the same t, or if the same t appears more than twice, it will probably return an error.

BUG(tunabay): Currently b=Cyclic does not seem to work at all. Find out the correct algorithm.

func (*CbSpline) At

func (sp *CbSpline) At(t float64) float64

At calculates and returns the S(t) value on the cubic spline. t must be in the range of minimum to maximum values in the t list passed to New(). The return value for t out of range is undefined.

Notes

Bugs

  • Currently b=Cyclic does not seem to work at all. Find out the correct algorithm.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL