Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number of spline basis functions #27

Closed
robertdj opened this issue Jan 23, 2022 · 2 comments
Closed

Number of spline basis functions #27

robertdj opened this issue Jan 23, 2022 · 2 comments

Comments

@robertdj
Copy link

Hi

Thank you for this package. I consider using it in another package, but there is a thing I don't understand -- from simple examples I expect to have fewer functions.

Consider the knot vector

using BSplines
knots = [0; 0; 0; 1; 1; 1]
basis = BSplineBasis(1, knots)

Here, length(basis) returns 5 as expected and plotting the function look right. But when increasing the order I run into trouble

basis = BSplineBasis(2, knots)

Here, length(basis) returns 6, but I expect 4. Consider the output of plot(basis)

basis2

I would index the functions from 0 through 3. I expect the 0th and 3rd functions to be constantly 0. The 1st and 2nd should be the two straight lines.
What are the rest?

This becomes a problem when constructing a Spline because it insists on having a larger coeffs vector than the number of basis functions I anticipate.

@hyrodium
Copy link

hyrodium commented Jan 23, 2022

Here, length(basis) returns 6, but I expect 4.

It seems the constructor BSplineBasis automatically inserts additional knots on the endpoints. (i.e. the knot vector will be converted from [0,0,0,1,1,1] to [0,0,0,0,1,1,1,1] for order 2 (polynomial degree 1). ) With these converted knot vector, number of B-spline functions is 6.

If you would like to have four B-spline functions with knots (0,1) and polynomial degree 1, the following script seems working fine here.

julia> basis = BSplineBasis(2, [0,0,1,1])
4-element BSplineBasis{Vector{Int64}}:
 order: 2
 breakpoints: [0, 0, 1, 1]

julia> length(basis)
4

Btw, I'm also working on another B-spline package, named BasicBSpline.jl. With this package, you can solve this issue like this:

julia> using BasicBSpline

julia> k = KnotVector(0,1)*3
KnotVector([0.0, 0.0, 0.0, 1.0, 1.0, 1.0])

julia> P = BSplineSpace{1}(k) # polynomial degree 1
BSplineSpace{1, Float64}(KnotVector([0.0, 0.0, 0.0, 1.0, 1.0, 1.0]))

julia> dim(P)
4

@hyrodium hyrodium mentioned this issue Jan 23, 2022
3 tasks
@robertdj
Copy link
Author

Thanks @hyrodium ! It makes sense that the constructor extends the knots based on the order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants