Added Neville extrapolation from 3 points

This commit is contained in:
sm
2014-01-12 03:30:47 -08:00
parent 9160c3224f
commit 1ed4830d51
2 changed files with 109 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
package govector
import (
"errors"
)
// explicitly implements Neville's algorithm for three points at very
// particular parameter values.
// TODO: update this to take an arbitrary parameter value, and arbitrary slice
// of Point2d
func Extrapolate(P []Point2d) (*Point2d, error) {
if len(P) != 3 {
return nil, errors.New("only works for len(P) == 3")
}
// P_{01} = -2 * P_0 + 3 * P_1
p01 := P[0].ToVector().Scale(-2.0).ToPoint().Add(P[1].ToVector().Scale(3.0))
// P_{12} = -1 * P_1 + 2 * P_2
p12 := P[1].ToVector().Scale(-1.0).ToPoint().Add(P[2].ToVector().Scale(2.0))
// P_{012} = 1/2 * P_{01} + 3/2 * P_{12}
p012 := p01.ToVector().Scale(-1.0 / 2.0).ToPoint().Add(p12.ToVector().Scale(3.0 / 2.0))
return &p012, nil
}