Skip to content

Commit ebca45d

Browse files
juliohmsglyon
authored andcommitted
Fix #166: Add example for parametric splines to README (#167)
* Add example for parametric splines to README Fix #166 * Add preview for parametric spline example * Update README.md * Fix syntax for allowed failures in .travis.yml * Fix .travis.yml
1 parent 046e535 commit ebca45d

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ julia:
55
- 0.6
66
- nightly
77
matrix:
8-
- allow_failures:
9-
- nightly
8+
allow_failures:
9+
- julia: nightly

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,34 @@ NoInterp
210210
whereby the coordinate of the selected input vector MUST be located on a grid point. Requests for off grid
211211
coordinates results in the throwing of an error.
212212

213+
## Parametric splines
214+
215+
Given a set a knots with coordinates `x(t)` and `y(t)`, a parametric spline `S(t) = (x(t),y(t))` parametrized by `t in [0,1]` can be constructed with the following code adapted from a [post](http://julia-programming-language.2336112.n4.nabble.com/Parametric-splines-td37794.html#a37818) by Tomas Lycken:
216+
217+
```julia
218+
using Interpolations
219+
220+
t = 0:.1:1
221+
x = sin.(2π*t)
222+
y = cos.(2π*t)
223+
A = hcat(x,y)
224+
225+
itp = scale(interpolate(A, (BSpline(Cubic(Natural())), NoInterp()), OnGrid()), t, 1:2)
226+
227+
tfine = 0:.01:1
228+
xs, ys = [itp[t,1] for t in tfine], [itp[t,2] for t in tfine]
229+
```
230+
231+
We can then plot the spline with:
232+
233+
```julia
234+
using Plots
235+
236+
scatter(x, y, label="knots")
237+
plot!(xs, ys, label="spline")
238+
```
239+
![parametric spline](doc/images/parametric_spline.png)
240+
213241
## Extrapolation
214242

215243
The call to `extrapolate` defines what happens if you try to index into the interpolation object with coordinates outside of `[1, size(data,d)]` in any dimension `d`. The implemented boundary conditions are `Throw`, `Flat`, `Linear`, `Periodic` and `Reflect`, with more options planned. `Periodic` and `Reflect` require that there is a method of `Base.mod` that can handle the indices used.

doc/images/parametric_spline.png

54.7 KB
Loading

0 commit comments

Comments
 (0)