Skip to content

Commit

Permalink
Update docs with ClosedInterval plots (#387)
Browse files Browse the repository at this point in the history
* update docs with `ClosedInterval` plots

* update offset parameter

* update docs with `bsplinesupport_R` and `bsplinesupport_I`

* update index

* update docstrings
  • Loading branch information
hyrodium authored Feb 25, 2024
1 parent 233b930 commit 9ed90d6
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 6 deletions.
57 changes: 55 additions & 2 deletions docs/src/math/bsplinebasis.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,59 @@ In these cases, each B-spline basis function ``B_{(i,2,k)}`` is coninuous, so [`
\operatorname{supp}(B_{(i,p,k)})=[k_{i},k_{i+p+1}]
```

[TODO: fig]
[`bsplinesupport`](@ref) returns this interval set.

```@example math_bsplinebasis
p = 2
k = KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0])
P = BSplineSpace{p}(k)
pl1 = plot([t->bsplinebasis₋₀(P,i,t) for i in 1:dim(P)], 0, 10, ylims=(0,1), label=false)
pl2 = plot(; yticks=nothing, legend=nothing)
for i in 1:dim(P)
plot!(pl2, bsplinesupport(P,i); offset=-i/10, linewidth=3, markersize=5, ylims=(-(dim(P)+1)/10, 1/10))
end
plot!(pl2, k; color=:black)
plot(pl1, pl2; layout=grid(2, 1, heights=[0.8 ,0.2]), link=:x)
savefig("bsplinesupport.png") # hide
nothing # hide
```

![](bsplinesupport.png)

[`bsplinesupport_R`](@ref) is the same as [`bsplinesupport`](@ref).

```@example math_bsplinebasis
pl = plot(; yticks=nothing, legend=nothing, size=(600,150))
for i in 1:dim(P)
plot!(pl, bsplinesupport_R(P,i); offset=-i/10, linewidth=3, markersize=5, ylims=(-(dim(P)+1)/10, 1/10))
end
plot!(pl, k; color=:black)
savefig("bsplinesupport_R.png") # hide
nothing # hide
```

![](bsplinesupport_R.png)

However, [`bsplinesupport_I`](@ref) is different from [`bsplinesupport`](@ref).
It returns ``[k_i,k_{i+p}] \cap [k_{1+p},k_{l-p}]`` instead.

```@example math_bsplinebasis
pl = plot(; yticks=nothing, legend=nothing, size=(600,150))
for i in 1:dim(P)
plot!(pl, bsplinesupport_I(P,i); offset=-i/10, linewidth=3, markersize=5, ylims=(-(dim(P)+1)/10, 1/10))
end
plot!(pl, k; color=:black)
savefig("bsplinesupport_I.png") # hide
nothing # hide
```

![](bsplinesupport_I.png)

```@repl math_bsplinebasis
bsplinesupport(P,1), bsplinesupport_R(P,1), bsplinesupport_I(P,1)
bsplinesupport(P,3), bsplinesupport_R(P,3), bsplinesupport_I(P,3)
```

## Partition of unity
!!! info "Thm. Partition of unity"
Expand Down Expand Up @@ -251,7 +303,8 @@ for p in 1:3
plot(P, legend=:topleft, label="B-spline basis (p=1)")
plot!(t->intervalindex(P,t),0,10, label="Interval index")
plot!(t->sum(bsplinebasis(P,i,t) for i in 1:dim(P)),0,10, label="Sum of B-spline basis")
plot!(k, label="knot vector")
plot!(domain(P); label="domain")
plot!(k; label="knot vector")
plot!([t->bsplinebasisall(P,1,t)[i] for i in 1:p+1],0,10, color=:black, label="bsplinebasisall (i=1)", ylim=(-1,8-2p))
savefig("bsplinebasisall-$(p).html") # hide
nothing # hide
Expand Down
50 changes: 46 additions & 4 deletions src/_BSplineSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,24 +368,66 @@ KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0])
julia> P = BSplineSpace{2}(k)
BSplineSpace{2, Float64, KnotVector{Float64}}(KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0]))
julia> bsplinesupport(P,1)
julia> bsplinesupport_R(P,1)
0.0 .. 5.5
julia> bsplinesupport(P,2)
julia> bsplinesupport_R(P,2)
1.5 .. 8.0
```
"""
bsplinesupport(P::BSplineSpace, i::Integer) = bsplinesupport_R(P,i)

function bsplinesupport_R(P::BSplineSpace{p}, i::Integer) where p
k = knotvector(P)
return k[i]..k[i+p+1]
end

@doc raw"""
Return the support of ``i``-th B-spline basis function.
```math
\operatorname{supp}(B_{(i,p,k)}|_I)=[k_{i},k_{i+p+1}] \cap I \qquad (I = [k_{1+p}, k_{l-p}])
```
# Examples
```jldoctest
julia> k = KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0])
KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0])
julia> P = BSplineSpace{2}(k)
BSplineSpace{2, Float64, KnotVector{Float64}}(KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0]))
julia> bsplinesupport_I(P,1)
2.5 .. 5.5
julia> bsplinesupport_I(P,2)
2.5 .. 8.0
```
"""
function bsplinesupport_I(P::BSplineSpace{p}, i::Integer) where p
return bsplinesupport_R(P,i) domain(P)
end

@doc raw"""
Return the support of ``i``-th B-spline basis function.
```math
\operatorname{supp}(B_{(i,p,k)})=[k_{i},k_{i+p+1}]
```
# Examples
```jldoctest
julia> k = KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0])
KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0])
julia> P = BSplineSpace{2}(k)
BSplineSpace{2, Float64, KnotVector{Float64}}(KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0]))
julia> bsplinesupport(P,1)
0.0 .. 5.5
julia> bsplinesupport(P,2)
1.5 .. 8.0
```
"""
const bsplinesupport = bsplinesupport_R

@doc raw"""
Internal methods for obtaining a B-spline space with one degree lower.
```math
Expand Down

0 comments on commit 9ed90d6

Please sign in to comment.