B-splines
BSplineKit.BSplines
— ModuleBSplines
Module defining B-spline bases and B-spline related functions.
B-spline bases
BSplineKit.BSplines.AbstractBSplineBasis
— TypeAbstractBSplineBasis{k,T}
Abstract type defining a B-spline basis, or more generally, a functional basis defined from B-splines.
The basis is represented by a B-spline order k
and a knot element type T
.
BSplineKit.BSplines.BSplineBasis
— TypeBSplineBasis{k}
B-spline basis for splines of order k
.
The basis is defined by a set of knots and by the B-spline order.
BSplineBasis(k, breakpoints::AbstractVector; augment = Val(true))
Create B-spline basis of order k
with the given breakpoints.
If augment = Val(true)
, breakpoints will be "augmented" so that boundary knots have multiplicity k
. Note that, if they are passed as a regular Vector
, the input may be modified. See augment_knots!
for details.
Examples
julia> breaks = range(-1, 1, length = 21)
-1.0:0.1:1.0
julia> B = BSplineBasis(5, breaks)
24-element BSplineBasis: order 5, domain [-1.0, 1.0]
This is equivalent to the above:
julia> B = BSplineBasis(BSplineOrder(5), breaks)
24-element BSplineBasis: order 5, domain [-1.0, 1.0]
Note that first and last knots have multiplicity $k = 5$:
julia> show(knots(B))
[-1.0, -1.0, -1.0, -1.0, -1.0, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.0, 1.0, 1.0, 1.0]
If augment = Val(false)
, input breakpoints are taken without modification as the knots $t_i$ of the B-spline basis. Note that the valid domain is reduced to $[-0.6, 0.6]$. The domain is always defined as the range $[t_k, t_{N + 1}]$, where $N$ is the length of the basis (below, $N = 16$).
julia> Bn = BSplineBasis(5, breaks, augment = Val(false))
16-element BSplineBasis: order 5, domain [-0.6, 0.6]
julia> show(knots(Bn))
-1.0:0.1:1.0
BSplineKit.BSplines.boundaries
— Functionboundaries(B::AbstractBSplineBasis)
Returns (xmin, xmax)
tuple with the boundaries of the domain supported by the basis.
BSplineKit.BSplines.order
— Functionorder(::Type{BSplineBasis}) -> Int
order(::Type{Spline}) -> Int
order(::BSplineOrder) -> Int
Returns order of B-splines as an integer.
BSplineKit.BSplines.knots
— Functionknots(g::BSplineBasis)
knots(g::Spline)
Returns the knots of the B-spline basis.
Base.getindex
— Functiongetindex(B::AbstractBSplineBasis, i, [T = Float64])
Get $i$-th basis function.
This is an alias for BasisFunction(B, i, T)
(see BasisFunction
for details).
The returned object can be evaluated at any point within the boundaries defined by the basis.
Examples
julia> B = BSplineBasis(BSplineOrder(4), -1:0.1:1)
23-element BSplineBasis: order 4, domain [-1.0, 1.0]
julia> B[6]
Basis function i = 6
from 23-element BSplineBasis: order 4, domain [-1.0, 1.0]
support: [-0.8, -0.4) (knots 6:10)
julia> B[6](-0.5)
0.16666666666666666
julia> B[6, Float32](-0.5)
0.16666667f0
julia> B[6](-0.5, Derivative(1))
-5.000000000000001
Base.length
— Methodlength(g::BSplineBasis)
Returns the number of B-splines composing a spline.
Basis functions
BSplineKit.BSplines.BasisFunction
— TypeBasisFunction{B <: AbstractBSplineBasis, T}
Describes a single basis function.
The basis function may belong to a BSplineBasis
(in which case it's effectively a B-spline), or to a basis derived from a B-spline basis (such as a RecombinedBSplineBasis
).
BasisFunction(basis::AbstractBSplineBasis, i::Int, [T = Float64])
Construct i-th basis function of the given basis.
The constructed function can be evaluated as b(x)
, returning a value of type T
.
(b::BasisFunction)(x, [op::AbstractDifferentialOp])
Evaluate basis function at coordinate x
.
To evaluate a derivative, pass Derivative(n)
as the op
argument, with n
the derivative order.
More general differential operators, such as Derivative(n) + λ Derivative(m)
, are also supported.
BSplineKit.BSplines.support
— Functionsupport(b::BasisFunction) -> UnitRange{Int}
Get range of knots supported by the basis function.
Returns the knot range i:j
such that the basis function support is $t ∈ [t_i, t_j)$.
support(B::AbstractBSplineBasis, i::Integer) -> UnitRange{Int}
Get range of knots supported by the $i$-th basis function.
BSplineKit.BSplines.common_support
— Functioncommon_support(b1::BasisFunction, b2::BasisFunction, ...) -> UnitRange{Int}
Get range of knots commonly supported by different basis functions.
If the supports don't intersect, an empty range is returned (e.g. 6:5
), following the behaviour of intersect
. The lack of intersection can be checked using isempty
, which returns true
for such a range.
BSplineKit.BSplines.evaluate
— Functionevaluate(B::AbstractBSplineBasis, i::Integer, x,
[op::AbstractDifferentialOp], [T=Float64])
Evaluate $i$-th basis function in the given basis at x
(can be a coordinate or a vector of coordinates).
To evaluate a derivative, pass Derivative(n)
as the op
argument, with n
the derivative order.
More general differential operators, such as Derivative(n) + λ Derivative(m)
, are also supported.
See also evaluate!
.
BSplineKit.BSplines.evaluate!
— Functionevaluate!(b::AbstractVector, B::BSplineBasis, i::Integer,
x::AbstractVector, args...)
Evaluate i-th basis function at positions x
and write result to b
.
See also evaluate
.
BSplineKit.BSplines.nonzero_in_segment
— Functionnonzero_in_segment(B::AbstractBSplineBasis, n::Int) -> UnitRange{Int}
Returns the range of basis functions that are non-zero in a given knot segment.
The $n$-th knot segment is defined by $Ω_n = [t_n, t_{n + 1}]$.
For BSplineBasis
and RecombinedBSplineBasis
, the number of non-zero functions in any given segment is generally equal to the B-spline order $k$. This number decreases near the borders, but this is not significant when B-spline knots have multiplicity $k$ there (as is the default).
For B-spline bases, and excepting the borders, the non-zero B-splines are $\left\{ b_i \right\}_{i = n - k + 1}^{n}$. This function thus returns (n - k + 1):N
when B
is a BSplineBasis
.
See also support
for the inverse operation.
Internals
BSplineKit.BSplines.BSplineOrder
— TypeBSplineOrder(k::Integer)
Specifies the B-spline order k
.
BSplineKit.BSplines.AugmentedKnots
— TypeAugmentedKnots{T,k} <: AbstractVector{T}
Pads from both sides a vector of B-spline breakpoints, making sure that the first and last values are repeated k
times.
BSplineKit.BSplines.augment_knots!
— Functionaugment_knots!(breaks::AbstractVector, k::Union{Integer,BSplineOrder})
Modifies the input breakpoints to make sure that the first and last knot have multiplicity k
for splines of order k
.
To prevent allocations, this function will modify the input when this is a standard Vector
. Otherwise, the input will be wrapped inside an AugmentedKnots
object.
It is assumed that the input breakpoints have multiplicity 1 at the borders. That is, border coordinates should not be repeated in the input.
BSplineKit.BSplines.multiplicity
— Functionmultiplicity(knots, i)
Determine multiplicity of knot knots[i]
.