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

Update docs #379

Merged
merged 5 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ makedocs(;
"B-spline space" => "math/bsplinespace.md",
"B-spline basis function" => "math/bsplinebasis.md",
"B-spline manifold" => "math/bsplinemanifold.md",
"Derivative" => "math/derivative.md",
"Rational B-spline manifold" => "math/rationalbsplinemanifold.md",
"Inclusive relationship" => "math/inclusive.md",
"Refinement" => "math/refinement.md",
"Rational B-spline manifold" => "math/rationalbsplinemanifold.md",
"Derivative" => "math/derivative.md",
"Fitting" => "math/fitting.md",
],
# "Differentiation" => [
Expand Down
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ isnondegenerate
isdegenerate(P::BSplineSpace)
BSplineManifold
unbounded_mapping
RationalBSplineManifold
```

```@docs
Expand Down
58 changes: 55 additions & 3 deletions docs/src/math/bsplinemanifold.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ nothing # hide

Higher dimensional tensor products ``\mathcal{P}[p^1,k^1]\otimes\cdots\otimes\mathcal{P}[p^d,k^d]`` are defined similarly.

## B-spline manifold
## Definition
B-spline manifold is a parametric representation of a shape.

!!! tip "Def. B-spline manifold"
Expand Down Expand Up @@ -86,7 +86,7 @@ unbounded_mapping(M, 1.2)

`unbounded_mapping(M,t...)` is a little bit faster than `M(t...)` because it does not check the domain.

### B-spline curve
## B-spline curve
```@example math_bsplinemanifold
## 1-dim B-spline manifold
p = 2 # degree of polynomial
Expand All @@ -103,7 +103,7 @@ nothing # hide
<object type="text/html" data="../1dim-manifold.html" style="width:100%;height:420px;"></object>
```

### B-spline surface
## B-spline surface
```@example math_bsplinemanifold
## 2-dim B-spline manifold
p = 2 # degree of polynomial
Expand All @@ -121,6 +121,58 @@ nothing # hide
<object type="text/html" data="../2dim-manifold.html" style="width:100%;height:420px;"></object>
```

**Paraboloid**
```@example math_bsplinemanifold
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("paraboloid.html") # hide
nothing # hide
```

```@raw html
<object type="text/html" data="../paraboloid.html" style="width:100%;height:420px;"></object>
```

**Hyperbolic paraboloid**
```@example math_bsplinemanifold
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("hyperbolicparaboloid.html") # hide
nothing # hide
```

```@raw html
<object type="text/html" data="../hyperbolicparaboloid.html" style="width:100%;height:420px;"></object>
```

## B-spline solid

```@example math_bsplinemanifold
k1 = k2 = KnotVector([0,0,1,1])
k3 = UniformKnotVector(-6:6)
P1 = BSplineSpace{1}(k1)
P2 = BSplineSpace{1}(k2)
P3 = BSplineSpace{3}(k3)
e₁(t) = SVector(cos(t),sin(t),0)
e₂(t) = SVector(-sin(t),cos(t),0)
a = cat([[e₁(t)*i+e₂(t)*j+SVector(0,0,t) for i in 0:1, j in 0:1] for t in -2:0.5:2]..., dims=3)
M = BSplineManifold(a,(P1,P2,P3))
plot(M; colorbar=false)
savefig("bsplinesolid.html") # hide
nothing # hide
```

```@raw html
<object type="text/html" data="../bsplinesolid.html" style="width:100%;height:420px;"></object>
```

## Affine commutativity
!!! info "Thm. Affine commutativity"
Let ``T`` be a affine transform ``V \to W``, then the following equality holds.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/math/bsplinespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Note that each element of the space ``\mathcal{P}[p,k]`` is a piecewise polynomi
## Degeneration

!!! tip "Def. Degeneration"
A B-spline space is said to be **non-degenerate** if its degree and knot vector satisfies following property:
A B-spline space **non-degenerate** if its degree and knot vector satisfies following property:
```math
\begin{aligned}
k_{i}&<k_{i+p+1} & (1 \le i \le l-p-1)
Expand Down
7 changes: 1 addition & 6 deletions docs/src/math/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
## Introduction
[B-spline](https://en.wikipedia.org/wiki/B-spline) is a mathematical object, and it has a lot of application. (e.g. Geometric representation: [NURBS](https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline), Interpolation, Numerical analysis: [IGA](https://en.wikipedia.org/wiki/Isogeometric_analysis))

In this page, we'll explain the mathematical definitions and properties of B-spline with Julia code.
Before running the code in the following section, you need to import packages:
```@example
using BasicBSpline
using Plots; plotly()
```
We will explain the mathematical definitions and properties of B-spline with Julia code in the following pages.

## Notice
Some of notations in this page are our original, but these are well-considered results.
Expand Down
124 changes: 114 additions & 10 deletions docs/src/math/rationalbsplinemanifold.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Rational B-spline manifold

```@setup math
## Setup

```@example math_rationalbsplinemanifold
using BasicBSpline
using BasicBSplineExporter
using StaticArrays
using LinearAlgebra
using Plots; plotly()
```

[Non-uniform rational basis spline (NURBS)](https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline) is also supported in BasicBSpline.jl package.

## Rational B-spline manifold
## Definition
Rational B-spline manifold is a parametric representation of a shape.

!!! tip "Def. Rational B-spline manifold"
Expand All @@ -23,13 +25,115 @@ Rational B-spline manifold is a parametric representation of a shape.
```
Where ``\bm{a}_{i^1,\dots,i^d}`` are called **control points**, and ``w_{i^1 \dots i^d}`` are called **weights**.

```@docs
RationalBSplineManifold
## Visualization with projection

A rational B-spline manifold in ``\mathbb{R}^d`` can be understanded as a projected B-spline manifold in ``\mathbb{R}^{d+1}``.
The next visuallzation this projection.

```@example math_rationalbsplinemanifold
# Define B-spline space
k = KnotVector([0.0, 1.5, 2.5, 5.0, 5.5, 8.0, 9.0, 9.5, 10.0])
P = BSplineSpace{3}(k)

# Define geometric parameters
a2 = [
SVector(-0.65, -0.20),
SVector(-0.20, +0.65),
SVector(-0.05, -0.10),
SVector(+0.75, +0.20),
SVector(+0.45, -0.65),
]
a3 = [SVector(p...,1) for p in a2]
w = [2.2, 1.3, 1.9, 2.1, 1.5]

# Define (rational) B-spline manifolds
R2 = RationalBSplineManifold(a2,w,(P,))
M3 = BSplineManifold(a3.*w,(P))
R3 = RationalBSplineManifold(a3,w,(P,))

# Plot
pl2 = plot(R2, xlims=(-1,1), ylims=(-1,1); color=:blue, linewidth=3, aspectratio=1, label=false)
pl3 = plot(R3; color=:blue, linewidth=3, controlpoints=(markersize=2,), label="Rational B-spline curve")
plot!(pl3, M3; color=:red, linewidth=3, controlpoints=(markersize=2,), label="B-spline curve")
for p in a3.*w
plot!(pl3, [0,p[1]], [0,p[2]], [0,p[3]], color=:black, linestyle=:dash, label=false)
end
for t in range(domain(P), length=51)
p = M3(t)
plot!(pl3, [0,p[1]], [0,p[2]], [0,p[3]], color=:red, linestyle=:dash, label=false)
end
surface!(pl3, [-1,1], [-1,1], ones(2,2); color=:green, colorbar=false, alpha=0.5)
plot(pl2, pl3; layout=grid(1,2, widths=[0.35, 0.65]), size=(780,500))
savefig("rational_bspline_manifold_projection.html") # hide
nothing # hide
```

## Properties
Similar to `BSplineManifold`, `RationalBSplineManifold` supports the following methods and properties.
```@raw html
<object type="text/html" data="../rational_bspline_manifold_projection.html" style="width:100%;height:520px;"></object>
```

## Conic sections

One of the great aspect of rational B-spline manifolds is exact shape representation of circles.
This is achieved as conic sections.

### Arc
```@example math_rationalbsplinemanifold
gr()
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
```

* currying
* `refinement`
* Affine commutativity
![](geometricmodeling-arc.png)

### Circle
```@example math_rationalbsplinemanifold
gr()
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 math_rationalbsplinemanifold
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
<object type="text/html" data="../geometricmodeling-torus.html" style="width:100%;height:420px;"></object>
```
Loading