Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hyrodium/basicbsplinefitting.jl
https://github.com/hyrodium/basicbsplinefitting.jl
Last synced: about 10 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/hyrodium/basicbsplinefitting.jl
- Owner: hyrodium
- License: mit
- Created: 2023-01-06T14:55:58.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-31T18:06:14.000Z (22 days ago)
- Last Synced: 2025-01-18T12:20:24.159Z (4 days ago)
- Language: Julia
- Size: 540 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BasicBSplineFitting
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://hyrodium.github.io/BasicBSpline.jl/dev/math-fitting/)
[![Coverage](https://codecov.io/gh/hyrodium/BasicBSplineFitting.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/hyrodium/BasicBSplineFitting.jl)This package provides `fittingcontrolpoints` and related functions.
These functions have been moved from [BasicBSpline.jl v0.9.0](https://github.com/hyrodium/BasicBSpline.jl/releases/tag/v0.9.0).## Fitting B-spline manifold
[Try on Desmos graphing calculator!](https://www.desmos.com/calculator/2hm3b1fbdf)
```julia
using BasicBSplineFittingp1 = 2
p2 = 2
k1 = KnotVector(-10:10)+p1*KnotVector([-10,10])
k2 = KnotVector(-10:10)+p2*KnotVector([-10,10])
P1 = BSplineSpace{p1}(k1)
P2 = BSplineSpace{p2}(k2)f(u1, u2) = SVector(2u1 + sin(u1) + cos(u2) + u2 / 2, 3u2 + sin(u2) + sin(u1) / 2 + u1^2 / 6) / 5
a = fittingcontrolpoints(f, (P1, P2))
M = BSplineManifold(a, (P1, P2))
save_png("fitting.png", M, unitlength=50, xlims=(-10,10), ylims=(-10,10))
```
![](docs/src/img/fitting_desmos.png)
![](docs/src/img/fitting.png)If the knot vector span is too coarse, the approximation will be coarse.
```julia
p1 = 2
p2 = 2
k1 = KnotVector(-10:5:10)+p1*KnotVector([-10,10])
k2 = KnotVector(-10:5:10)+p2*KnotVector([-10,10])
P1 = BSplineSpace{p1}(k1)
P2 = BSplineSpace{p2}(k2)f(u1, u2) = SVector(2u1 + sin(u1) + cos(u2) + u2 / 2, 3u2 + sin(u2) + sin(u1) / 2 + u1^2 / 6) / 5
a = fittingcontrolpoints(f, (P1, P2))
M = BSplineManifold(a, (P1, P2))
save_png("fitting_coarse.png", M, unitlength=50, xlims=(-10,10), ylims=(-10,10))
```
![](docs/src/img/fitting_coarse.png)## Draw smooth vector graphics
```julia
p = 3
k = KnotVector(range(-2π,2π,length=8))+p*KnotVector(-2π,2π)
P = BSplineSpace{p}(k)f(u) = SVector(u,sin(u))
a = fittingcontrolpoints(f, P)
M = BSplineManifold(a, P)
save_svg("sine-curve.svg", M, unitlength=50, xlims=(-2,2), ylims=(-8,8))
save_svg("sine-curve_no-points.svg", M, unitlength=50, xlims=(-2,2), ylims=(-8,8), points=false)
```
![](docs/src/img/sine-curve.svg)
![](docs/src/img/sine-curve_no-points.svg)This is useful when you edit graphs (or curves) with your favorite vector graphics editor.
![](docs/src/img/inkscape.png)
See [Plotting smooth graphs with Julia](https://forem.julialang.org/hyrodium/plotting-smooth-graphs-with-julia-6mj) for more tutorials.