From 4413b301960c14b5a08fd6de04879ebe44aab26a Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 10 Feb 2024 10:42:28 +0900 Subject: [PATCH 1/5] update docs --- docs/src/math/bsplinebasis.md | 7 +++---- docs/src/math/rationalbsplinemanifold.md | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/src/math/bsplinebasis.md b/docs/src/math/bsplinebasis.md index d910773d..5c42d2c8 100644 --- a/docs/src/math/bsplinebasis.md +++ b/docs/src/math/bsplinebasis.md @@ -274,6 +274,7 @@ end Let ``X_1, \dots, X_n`` be i.i.d. random variables with ``X_i \sim U(0,1)``, then the probability density function of ``X_1+\cdots+X_n`` can be obtained via `BasicBSpline.uniform_bsplinebasis_kernel(Val(n-1),t)`. ```@example math_bsplinebasis +gr() N = 100000 # polynomial degree 0 plot1 = histogram([rand() for _ in 1:N], normalize=true, label=false) @@ -289,10 +290,8 @@ plot4 = histogram([rand()+rand()+rand()+rand() for _ in 1:N], normalize=true, la plot!(t->BasicBSpline.uniform_bsplinebasis_kernel(Val(3),t), label=false) # plot all plot(plot1,plot2,plot3,plot4) -savefig("histogram-uniform.html") # hide +savefig("histogram-uniform.png") # hide nothing # hide ``` -```@raw html - -``` +![](histogram-uniform.png) diff --git a/docs/src/math/rationalbsplinemanifold.md b/docs/src/math/rationalbsplinemanifold.md index bf305671..58968d91 100644 --- a/docs/src/math/rationalbsplinemanifold.md +++ b/docs/src/math/rationalbsplinemanifold.md @@ -87,7 +87,8 @@ t = 1 # angle in radians a = [SVector(1,0), SVector(1,tan(t/2)), SVector(cos(t),sin(t))] w = [1,cos(t/2),1] M = RationalBSplineManifold(a,w,P) -plot(M, xlims=(0,1.1), ylims=(0,1.1), aspectratio=1) +plot([cosd(t) for t in 0:360], [sind(t) for t in 0:360]; xlims=(-1.1,1.1), ylims=(-1.1,1.1), aspectratio=1, label="circle", color=:gray, linestyle=:dash) +plot!(M; label="Rational B-spline curve") savefig("geometricmodeling-arc.png") # hide nothing # hide ``` From 25045017440b6fcbe1477367fe9f40ccecdfee7d Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 10 Feb 2024 14:05:26 +0900 Subject: [PATCH 2/5] remove dot --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 55ad3a78..33bc6c5f 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Basic (mathematical) operations for B-spline functions and related things with J [![Coverage](https://codecov.io/gh/hyrodium/BasicBSpline.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/hyrodium/BasicBSpline.jl) [![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) [![DOI](https://zenodo.org/badge/258791290.svg)](https://zenodo.org/badge/latestdoi/258791290) -[![BasicBSpline Downloads](https://shields.io/endpoint?url=https://pkgs.genieframework.com/api/v1/badge/BasicBSpline)](https://pkgs.genieframework.com?packages=BasicBSpline). +[![BasicBSpline Downloads](https://shields.io/endpoint?url=https://pkgs.genieframework.com/api/v1/badge/BasicBSpline)](https://pkgs.genieframework.com?packages=BasicBSpline) ![](docs/src/img/BasicBSplineLogo.png) From ecad282928c9370b0f99d7948aacf2ed2db84a9c Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 10 Feb 2024 15:30:35 +0900 Subject: [PATCH 3/5] remove geometric modeling page --- docs/make.jl | 1 - docs/src/geometricmodeling.md | 101 ---------------------------------- 2 files changed, 102 deletions(-) delete mode 100644 docs/src/geometricmodeling.md diff --git a/docs/make.jl b/docs/make.jl index 6fd1d322..c6b05bc4 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -75,7 +75,6 @@ makedocs(; "PlotlyJS.jl" => "visualization/plotlyjs.md", "BasicBSplineExporter.jl" => "visualization/basicbsplineexporter.md", ], - "Geometric modeling" => "geometricmodeling.md", "Interpolations" => "interpolations.md", "API" => "api.md", ], diff --git a/docs/src/geometricmodeling.md b/docs/src/geometricmodeling.md deleted file mode 100644 index afe52b78..00000000 --- a/docs/src/geometricmodeling.md +++ /dev/null @@ -1,101 +0,0 @@ -# Geometric modeling - -## Setup - -```@example geometricmodeling -using BasicBSpline -using StaticArrays -using Plots -using LinearAlgebra -gr() -``` - -## Arc -```@example geometricmodeling -p = 2 -k = KnotVector([0,0,0,1,1,1]) -P = BSplineSpace{p}(k) -t = 1 # angle in radians -a = [SVector(1,0), SVector(1,tan(t/2)), SVector(cos(t),sin(t))] -w = [1,cos(t/2),1] -M = RationalBSplineManifold(a,w,P) -plot(M, xlims=(0,1.1), ylims=(0,1.1), aspectratio=1) -savefig("geometricmodeling-arc.png") # hide -nothing # hide -``` - -![](geometricmodeling-arc.png) - -## Circle -```@example geometricmodeling -p = 2 -k = KnotVector([0,0,0,1,1,2,2,3,3,4,4,4]) -P = BSplineSpace{p}(k) -a = [normalize(SVector(cosd(t), sind(t)), Inf) for t in 0:45:360] -w = [ifelse(isodd(i), √2, 1) for i in 1:9] -M = RationalBSplineManifold(a,w,P) -plot(M, xlims=(-1.2,1.2), ylims=(-1.2,1.2), aspectratio=1) -savefig("geometricmodeling-circle.png") # hide -nothing # hide -``` - -![](geometricmodeling-circle.png) - -## Torus -```@example geometricmodeling -plotly() -R1 = 3 -R2 = 1 - -A = push.(a, 0) - -a1 = (R1+R2)*A -a5 = (R1-R2)*A -a2 = [p+R2*SVector(0,0,1) for p in a1] -a3 = [p+R2*SVector(0,0,1) for p in R1*A] -a4 = [p+R2*SVector(0,0,1) for p in a5] -a6 = [p-R2*SVector(0,0,1) for p in a5] -a7 = [p-R2*SVector(0,0,1) for p in R1*A] -a8 = [p-R2*SVector(0,0,1) for p in a1] - -a = hcat(a1,a2,a3,a4,a5,a6,a7,a8,a1) -M = RationalBSplineManifold(a,w*w',P,P) -plot(M) -savefig("geometricmodeling-torus.html") # hide -nothing # hide -``` - -```@raw html - -``` - -## Paraboloid -```@example geometricmodeling -plotly() -p = 2 -k = KnotVector([-1,-1,-1,1,1,1]) -P = BSplineSpace{p}(k) -a = [SVector(i,j,2i^2+2j^2-2) for i in -1:1, j in -1:1] -M = BSplineManifold(a,P,P) -plot(M) -savefig("geometricmodeling-paraboloid.html") # hide -nothing # hide -``` - -```@raw html - -``` - -## Hyperbolic paraboloid -```@example geometricmodeling -plotly() -a = [SVector(i,j,2i^2-2j^2) for i in -1:1, j in -1:1] -M = BSplineManifold(a,P,P) -plot(M) -savefig("geometricmodeling-hyperbolicparaboloid.html") # hide -nothing # hide -``` - -```@raw html - -``` From 3a1fdb33e11fcd48307f2449ce94dc9f331dc858 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 10 Feb 2024 15:30:55 +0900 Subject: [PATCH 4/5] update fitting page --- docs/src/api.md | 1 + docs/src/math/fitting.md | 61 ++++++++++++++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/docs/src/api.md b/docs/src/api.md index 81de6cb6..5e65c880 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -30,6 +30,7 @@ isdegenerate(P::BSplineSpace) BSplineManifold unbounded_mapping RationalBSplineManifold +fittingcontrolpoints ``` ```@docs diff --git a/docs/src/math/fitting.md b/docs/src/math/fitting.md index 0b135d3b..3fd8542d 100644 --- a/docs/src/math/fitting.md +++ b/docs/src/math/fitting.md @@ -1,23 +1,18 @@ # Fitting with B-spline manifold -The following functions such as `fittingcontolpoints` were provided from BasicBSpline.jl before v0.9.0. -From BasicBSpline v0.9.0, these functions are moved to [BasicBSplineFitting](https://github.com/hyrodium/BasicBSplineFitting.jl). - -```@setup math +## Setup +```@example math_fitting using BasicBSpline using BasicBSplineFitting -using BasicBSplineExporter using StaticArrays -using Plots; plotly() +using Plots ``` -Fitting with least squares method. +## Fitting with least squares -```@docs -fittingcontrolpoints -``` +[`fittingcontrolpoints`](@ref) function -```@example math +```@example math_fitting p1 = 2 p2 = 2 k1 = KnotVector(-10:10)+p1*KnotVector([-10,10]) @@ -29,9 +24,51 @@ f(u1, u2) = SVector(2u1 + sin(u1) + cos(u2) + u2 / 2, 3u2 + sin(u2) + sin(u1) / a = fittingcontrolpoints(f, (P1, P2)) M = BSplineManifold(a, (P1, P2)) -save_png("fitting.png", M, unitlength=50, xlims=(-10,10), ylims=(-10,10)) +gr() +plot(M; xlims=(-10,10), ylims=(-10,10), aspectratio=1) +savefig("fitting.png") # hide +nothing # hide ``` ![](fitting.png) [Try on Desmos graphing graphing calculator!](https://www.desmos.com/calculator/2hm3b1fbdf) ![](../img/fitting_desmos.png) + + +### Cardioid (planar curve) +```@example math_fitting +f(t) = SVector((1+cos(t))*cos(t),(1+cos(t))*sin(t)) +p = 3 +k = KnotVector(range(0,2π,15)) + p * KnotVector([0,2π]) + 2 * KnotVector([π]) +P = BSplineSpace{p}(k) +a = fittingcontrolpoints(f, P) +M = BSplineManifold(a, P) + +gr() +plot(M; aspectratio=1) +savefig("plots-cardioid.html") # hide +nothing # hide +``` + +```@raw html + +``` + +### Helix (spatial curve) +```@example math_fitting +f(t) = SVector(cos(t),sin(t),t) +p = 3 +k = KnotVector(range(0,6π,15)) + p * KnotVector([0,6π]) +P = BSplineSpace{p}(k) +a = fittingcontrolpoints(f, P) +M = BSplineManifold(a, P) + +plotly() +plot(M) +savefig("plots-helix.html") # hide +nothing # hide +``` + +```@raw html + +``` From 69c285050a838d0e4b93782d547ea97126fe9dc5 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 10 Feb 2024 15:32:13 +0900 Subject: [PATCH 5/5] remove plots.jl page --- docs/make.jl | 1 - docs/src/visualization/plots.md | 156 -------------------------------- 2 files changed, 157 deletions(-) delete mode 100644 docs/src/visualization/plots.md diff --git a/docs/make.jl b/docs/make.jl index c6b05bc4..4f7536a8 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -71,7 +71,6 @@ makedocs(; # "ChainRules" => "chainrules.md" # ], "Visualization" => [ - "Plots.jl" => "visualization/plots.md", "PlotlyJS.jl" => "visualization/plotlyjs.md", "BasicBSplineExporter.jl" => "visualization/basicbsplineexporter.md", ], diff --git a/docs/src/visualization/plots.md b/docs/src/visualization/plots.md deleted file mode 100644 index 77384c4d..00000000 --- a/docs/src/visualization/plots.md +++ /dev/null @@ -1,156 +0,0 @@ -# Plots.jl - -`BasicBSpline.jl` has a dependency on [`RecipesBase.jl`](https://github.com/JuliaPlots/RecipesBase.jl). -This means, users can easily visalize instances defined in `BasicBSpline`. -In this section, we will provide some plottig examples. - -```@setup plots -using BasicBSpline -using BasicBSplineFitting -using StaticArrays -using Plots; plotly() -``` - -## `BSplineSpace` - -```@example plots -k = KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0]) -P0 = BSplineSpace{0}(k) # 0th degree piecewise polynomial space -P1 = BSplineSpace{1}(k) # 1st degree piecewise polynomial space -P2 = BSplineSpace{2}(k) # 2nd degree piecewise polynomial space -P3 = BSplineSpace{3}(k) # 3rd degree piecewise polynomial space -plot( - plot([t->bsplinebasis(P0,i,t) for i in 1:dim(P0)], 0, 10, ylims=(0,1), legend=false, title="0th polynomial degree"), - plot([t->bsplinebasis(P1,i,t) for i in 1:dim(P1)], 0, 10, ylims=(0,1), legend=false, title="1st polynomial degree"), - plot([t->bsplinebasis(P2,i,t) for i in 1:dim(P2)], 0, 10, ylims=(0,1), legend=false, title="2nd polynomial degree"), - plot([t->bsplinebasis(P3,i,t) for i in 1:dim(P3)], 0, 10, ylims=(0,1), legend=false, title="3rd polynomial degree"), -) -savefig("plots-bsplinebasis-raw.html") # hide -nothing # hide -``` - -```@raw html - -``` - -```@example plots -k = KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0]) -P0 = BSplineSpace{0}(k) # 0th degree piecewise polynomial space -P1 = BSplineSpace{1}(k) # 1st degree piecewise polynomial space -P2 = BSplineSpace{2}(k) # 2nd degree piecewise polynomial space -P3 = BSplineSpace{3}(k) # 3rd degree piecewise polynomial space -plot( - plot(P0, ylims=(0,1), legend=false, title="0th polynomial degree"), - plot(P1, ylims=(0,1), legend=false, title="1st polynomial degree"), - plot(P2, ylims=(0,1), legend=false, title="2nd polynomial degree"), - plot(P3, ylims=(0,1), legend=false, title="3rd polynomial degree"), - layout=(2,2), -) -savefig("plots-bsplinebasis.html") # hide -nothing # hide -``` - -```@raw html - -``` - -## `BSplineDerivativeSpace` - -```@example plots -k = KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0]) -P = BSplineSpace{3}(k) -plot( - plot(BSplineDerivativeSpace{0}(P), label="0th derivative", color=:black), - plot(BSplineDerivativeSpace{1}(P), label="1st derivative", color=:red), - plot(BSplineDerivativeSpace{2}(P), label="2nd derivative", color=:green), - plot(BSplineDerivativeSpace{3}(P), label="3rd derivative", color=:blue), -) -savefig("plots-bsplinebasisderivative.html") # hide -nothing # hide -``` - -```@raw html - -``` - -## `BSplineManifold` - -### Cardioid (planar curve) -```@example plots -f(t) = SVector((1+cos(t))*cos(t),(1+cos(t))*sin(t)) -p = 3 -k = KnotVector(range(0,2π,15)) + p * KnotVector([0,2π]) + 2 * KnotVector([π]) -P = BSplineSpace{p}(k) -a = fittingcontrolpoints(f, P) -M = BSplineManifold(a, P) - -plot(M) -savefig("plots-cardioid.html") # hide -nothing # hide -``` - -```@raw html - -``` - -### Helix (spatial curve) -```@example plots -f(t) = SVector(cos(t),sin(t),t) -p = 3 -k = KnotVector(range(0,6π,15)) + p * KnotVector([0,6π]) -P = BSplineSpace{p}(k) -a = fittingcontrolpoints(f, P) -M = BSplineManifold(a, P) - -plot(M) -savefig("plots-helix.html") # hide -nothing # hide -``` - -```@raw html - -``` - -### B-spline surface - -```@example plots -p1 = 2 -p2 = 3 -k1 = KnotVector(1:10) -k2 = KnotVector(1:20) -P1 = BSplineSpace{p1}(k1) -P2 = BSplineSpace{p2}(k2) -a = [SVector(i-j^2/20, j+i^2/10, sin((i+j)/2)+randn()) for i in 1:dim(P1), j in 1:dim(P2)] -M = BSplineManifold(a,(P1,P2)) -plot(M) - -savefig("plots-surface.html") # hide -nothing # hide -``` - -```@raw html - -``` - - -## `RationalBSplineManifold` - -```@example plots -k = KnotVector([0,0,0,1,1,1]) -P = BSplineSpace{2}(k) -a = [SVector(1,0),SVector(1,1),SVector(0,1)] -w = [1,1/√2,1] -M = BSplineManifold(a,P) -R = RationalBSplineManifold(a,w,P) -ts = 0:0.01:2 -plot(cospi.(ts),sinpi.(ts), label="circle") -plot!(M, label="B-spline curve") -plot!(R, label="Rational B-spline curve") - -savefig("plots-arc.html") # hide -nothing # hide -``` - -```@raw html - -```