poly

package
v0.0.0-...-9c88ebf Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bezier

type Bezier []d2.Pt

Bezier fulfills Coefficients representing a Bezier as a polynomial.

func (Bezier) Coefficient

func (b Bezier) Coefficient(idx int) d2.V

Coefficient at the given index of the polynomial representation of the Bezier curve.

func (Bezier) Len

func (b Bezier) Len() int

Len of the underlying slice

type Coefficients

type Coefficients interface {
	Coefficient(idx int) d2.V
	Len() int
}

Coefficients wraps the concept of a list of d2.V. It must return the length and be able to return the coefficient at any index.

type Derivative

type Derivative struct {
	Coefficients
}

Derivative of the underlying Coefficients.

func (Derivative) Coefficient

func (d Derivative) Coefficient(idx int) d2.V

Coefficient at idx is (idx+1)*Coefficient(idx+1).

func (Derivative) Len

func (d Derivative) Len() int

Len is one less than the underlying Coefficients.

type Poly

type Poly struct {
	Coefficients
}

Poly is a 2D polynomial curve.

func New

func New(pts ...d2.V) Poly

New polynomial curve

func NewBezier

func NewBezier(pts []d2.Pt) Poly

NewBezier creates a Polynomial from the points used to define a Bezier curve.

func (Poly) Add

func (p Poly) Add(p2 Poly) Poly

Add creates a new polynomial by summinging p with p2.

func (Poly) Copy

func (p Poly) Copy(buf []d2.V) Poly

Copy the coefficients into an instance of Slice. The provided buffer will be used if it has sufficient capacity.

func (Poly) LineIntersections

func (p Poly) LineIntersections(l line.Line, buf []float64) []float64

LineIntersections fulfills line.Intersector and returns the intersections relative to the line.

func (Poly) Multiply

func (p Poly) Multiply(p2 Poly) Poly

Multiply creates a new polynomial by taking the produce of p with p2.

func (Poly) PolyLineIntersections

func (p Poly) PolyLineIntersections(l line.Line, buf []float64) []float64

PolyLineIntersections returns the intersection points relative to the Polynomial curve.

func (Poly) Pt1

func (p Poly) Pt1(t0 float64) d2.Pt

Pt1 returns the point on the curve at t0.

func (Poly) V

func (p Poly) V() V

V returns and instace of V that holds the derivative of p.

func (Poly) V1

func (p Poly) V1(t0 float64) d2.V

V1 takes the derivate of p at t0.

func (Poly) V1c0

func (p Poly) V1c0() d2.V1

V1c0 returns and instance of V fulfilling d2.V1 and caching the derivative. Note that this is still not buffered, so for repeated calls, make a copy to reduce duplicated work.

func (Poly) X

func (p Poly) X() poly1d.Poly

X returns the 1D polynomial formed by the X values.

func (Poly) Y

func (p Poly) Y() poly1d.Poly

X returns the 1D polynomial formed by the Y values.

type Product

type Product [2]Coefficients

Produce of two Coefficients.

func (Product) Coefficient

func (p Product) Coefficient(idx int) d2.V

Coefficient of the product at the given index.

func (Product) Len

func (p Product) Len() int

Len of the product of the Coefficients.

type Slice

type Slice []d2.V

Slice fulfills Coefficients using a Slice.

func Buf

func Buf(ln int, buf []d2.V) Slice

Buf returns and instance of Slice. It will use the provided buffer if possible.

func (Slice) Coefficient

func (s Slice) Coefficient(idx int) d2.V

Coefficient returns the d2.V at the given index if it is in range, otherwise it returns d2.V{0,0}.

func (Slice) Len

func (s Slice) Len() int

Len returns the length of the underlying slice.

type Sum

type Sum [2]Coefficients

Sum fulfills Coefficients by adding the two underlying Coefficients together.

func (Sum) Coefficient

func (s Sum) Coefficient(idx int) d2.V

Coefficient returns the sum of both Coefficients at the given index.

func (Sum) Len

func (s Sum) Len() int

Len returns the longer of the two underlying Coefficients.

type V

type V struct {
	Poly
}

V represents the derivative of a Polynomial and will return d2.V instead of d2.Pt.

func (V) Copy

func (v V) Copy(buf []d2.V) V

Copy the coefficients into an instance of Slice. The provided buffer will be used if it has sufficient capacity.

func (V) V1

func (v V) V1(t0 float64) d2.V

V1 returns V at t0.

type X

type X struct{ Coefficients }

X converts and instance of Coefficients into a set of 1D Coefficients using their X components.

func (X) Coefficient

func (x X) Coefficient(idx int) float64

Coefficient returns the X value of the underlying Coefficients.

func (X) Len

func (x X) Len() int

Len returns the Len of the underlying Coefficients.

type Y

type Y struct{ Coefficients }

Y converts and instance of Coefficients into a set of 1D Coefficients using their Y components.

func (Y) Coefficient

func (y Y) Coefficient(idx int) float64

Coefficient returns the Y value of the underlying Coefficients.

func (Y) Len

func (y Y) Len() int

Len returns the Len of the underlying Coefficients.

Jump to

Keyboard shortcuts

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