Questions tagged [spline]

A spline is a sufficiently smooth polynomial function that is piecewise-defined, and possesses a high degree of smoothness at the places where the polynomial pieces connect

spline
Filter by
Sorted by
Tagged with
174 votes
14 answers
163k views

how to draw smooth curve through N points using javascript HTML5 canvas?

For a drawing application, I'm saving the mouse movement coordinates to an array then drawing them with lineTo. The resulting line is not smooth. How can I produce a single curve between all the ...
Homan's user avatar
  • 26.1k
4 votes
4 answers
29k views

Proper implementation of cubic spline interpolation

I was using one of the proposed algorithms out there but the results are very bad. I implemented the wiki algorithm in Java (code below). x(0) is points.get(0), y(0) is values[points.get(0)], α is ...
Mr Jedi's user avatar
  • 34.2k
54 votes
6 answers
45k views

Closest point on a cubic Bezier curve?

How can I find the point B(t) along a cubic Bezier curve that is closest to an arbitrary point P in the plane?
Adrian Lopez's user avatar
  • 1,724
10 votes
5 answers
6k views

How to plot line (polygonal chain) with numpy/scipy/matplotlib with minimal smoothing

I am trying to plot a line in matplotlib.. I am searching for the right type of interpolation.. I want something like this where every line is smoothed. I tried several combination of scipy and ...
gc5's user avatar
  • 9,668
4 votes
2 answers
3k views

get x-value given y-value: general root finding for linear / non-linear interpolation function

I am interested in a general root finding problem for an interpolation function. Suppose I have the following (x, y) data: set.seed(0) x <- 1:10 + runif(10, -0.1, 0.1) y <- rnorm(10, 3, 1) as ...
Zheyuan Li's user avatar
  • 72.5k
27 votes
8 answers
85k views

How do I implement a Bézier curve in C++?

I'd like to implement a Bézier curve. How should I go about creating a quadratic curve? void printQuadCurve(float delta, Vector2f p0, Vector2f p1, Vector2f p2); Clearly we'd need to use linear ...
Nick Bolton's user avatar
17 votes
2 answers
10k views

Fast b-spline algorithm with numpy/scipy

I need to compute bspline curves in python. I looked into scipy.interpolate.splprep and a few other scipy modules but couldn't find anything that readily gave me what I needed. So i wrote my own ...
Fnord's user avatar
  • 5,575
12 votes
2 answers
7k views

Getting spline equation from UnivariateSpline object

I'm using UnivariateSpline to construct piecewise polynomials for some data that I have. I would then like to use these splines in other programs (either in C or FORTRAN) and so I would like to ...
FrenchKheldar's user avatar
31 votes
6 answers
29k views

Smoothing a hand-drawn curve

I've got a program that allows users to draw curves. But these curves don't look nice - they look wobbly and hand-drawn. So I want an algorithm that will automatically smooth them. I know there are ...
thund's user avatar
  • 1,902
0 votes
2 answers
3k views

Highcharts spline dataLabels overlapping

I have a question about highchart's overlapping data labels. I have 2 spline data series and as you can see here http://jsfiddle.net/3E8V4/ some data labels are overlapping. Question here is: is this ...
Sobis's user avatar
  • 1,395
21 votes
1 answer
12k views

mgcv: How to set number and / or locations of knots for splines

I want to use function gam in mgcv packages: x <- seq(0,60, len =600) y <- seq(0,1, len=600) prova <- gam(y ~ s(x, bs='cr') can I set the number of knots in s()? and then can I know ...
memy's user avatar
  • 249
16 votes
2 answers
13k views

Smooth spline representation of an arbitrary contour, f(length) --> x,y

Suppose I have a set of x,y coordinates that mark points along contour. Is there a way that I can build a spline representation of the contour that I can evaluate at a particular position along its ...
ali_m's user avatar
  • 73.2k
52 votes
5 answers
53k views

Python natural smoothing splines

I am trying to find a python package that would give an option to fit natural smoothing splines with user selectable smoothing factor. Is there an implementation for that? If not, how would you use ...
Niko Fohr's user avatar
  • 30.7k
19 votes
1 answer
22k views

How to add legend to geom_smooth in ggplot in R

Have a problem of adding legend to different smooth in ggplot. library(splines) library(ggplot2) temp <- data.frame(x = rnorm(200, 20, 15), y = rnorm(200, 30, 8)) ggplot(data = ...
R.Arkhipov's user avatar
13 votes
1 answer
10k views

Extract knots, basis, coefficients and predictions for P-splines in adaptive smooth

I'm using the mgcv package to fit some polynomial splines to some data via: x.gam <- gam(cts ~ s(time, bs = "ad"), data = x.dd, family = poisson(link = "log")) I'm ...
Mael's user avatar
  • 1,302
9 votes
1 answer
8k views

Fit Curve-Spline to 3D Point Cloud

Objective I have a 3D facet model (e.g. .off file) which can for example look like a pipe/tube (see example picture). The goal is to derive an approximate spline (best case combination of lines and ...
BennyS's user avatar
  • 145
9 votes
2 answers
33k views

Spline interpolation in 3D in python

I am searching the equivalent Matlab command Vq = interp3(X,Y,Z,V,Xq,Yq,Zq) in Python. In Matlab I can use the method 'spline' interpolation, which I can not find in python for 3D data. There ...
cerv21's user avatar
  • 341
5 votes
2 answers
3k views

How do Bezier Patches work in the Utah Teapot?

I prematurely posted a code golf challenge to draw the Utah Teapot using this dataset (just the teapot). (Revised and Posted teapot challenge) But when I looked deeper at the data in order to whip up ...
luser droog's user avatar
  • 19.4k
1 vote
2 answers
3k views

Cubic spline interpolation vs polynomial interpolation

I am asked to investigate the different types of interpolation using Matlab for the following points: x = [32 34 35 36 37 38] y = [26 28 31 30 29 25] and find the values for f(33), f(33.5) and f(35)...
P.ython's user avatar
  • 63
22 votes
4 answers
7k views

How to approximate a half-cosine curve with bezier paths in SVG?

Suppose I want to approximate a half-cosine curve in SVG using bezier paths. The half cosine should look like this: and runs from [x0,y0] (the left-hand control point) to [x1,y1] (the right-hand one)....
janesconference's user avatar
19 votes
1 answer
16k views

spline interpolation coefficients of a line curve in 3d space

I am new to python. I have a line curve in the 3D space defined by a set of given points. Can anyone suggest how I can use the interpolate with spline functions of the scipy package to get the spline ...
Yannis's user avatar
  • 221
17 votes
3 answers
41k views

How does the centripetal Catmull–Rom spline work?

From this site, which seems to have the most detailed information about Catmull-Rom splines, it seems that four points are needed to create the spline. However, it does not mention how the points p0 ...
meds's user avatar
  • 22.5k
14 votes
2 answers
13k views

Math: Ease In, ease Out a displacement using Hermite curve with time constraint

I'm trying to write a method that interpolates from 0 to x (position of an object in one dimension) over time using acceleration at the beginning and deceleration at the end (ease out / ease in) with ...
742's user avatar
  • 3,049
13 votes
3 answers
3k views

Calculate a 2D spline curve in R

I'm trying to calculate a Bezier-like spline curve that passes through a sequence of x-y coordinates. An example would be like the following output from the cscvn function in Matlab (example link): I ...
Marc in the box's user avatar
11 votes
3 answers
14k views

The intersection point between a spline and a line

I'm trying to find a way to calculate the intersection between a b-spline and a straight line. So far Google hasn't been much help.
user31238's user avatar
  • 119
11 votes
3 answers
19k views

How to make a line curve through points

I'm looking for a way to make a line curve through a number of points. It would be preferable to use 3 points although I've considered that in order to give context to the angle of the line entering a ...
James C's user avatar
  • 484
8 votes
1 answer
10k views

Three.JS Object following a spline path - rotation / tanget issues & constant speed issue

I think my issue is similar to: Orient object's rotation to a spline point tangent in THREE.JS but I can't access the jsfiddle's properly and I struggled with the second part of the explanation. ...
jayfield1979's user avatar
7 votes
3 answers
1k views

Transform 2d spline function f(t) into f(x)

So I've got a special case set of cubic splines, whose 2d control points will always result in a curve that will never cross itself in the x axis. That is, the curves look like they could be a simple ...
vercellop's user avatar
  • 563
6 votes
3 answers
7k views

Incrementally display three.js TubeGeometry

I am able to display a THREE.TubeGeometry figure as follows Code below, link to jsbin <html> <body> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r75/three.js"></...
tubby's user avatar
  • 2,134
6 votes
1 answer
4k views

Export fitted regression splines (constructed by 'bs' or 'ns') as piecewise polynomials

Take for instance the following one-knot, degree two, spline: library(splines) library(ISLR) fit.spline <- lm(wage~bs(age, knots=c(42), degree=2), data=Wage) summary(fit.spline) I see estimates ...
shide's user avatar
  • 63
4 votes
2 answers
17k views

How to get confidence interval for smooth.spline?

I have used smooth.spline to estimate a cubic spline for my data. But when I calculate the 90% point-wise confidence interval using equation, the results seems to be a little bit off. Can someone ...
Yu Deng's user avatar
  • 1,061
3 votes
3 answers
6k views

Is there an R library that estimates a multivariate natural cubic spline (or similar) function?

note: originally posted on Cross Validated (stats SE) on 07-26-2011, with no correct answers to date. Background I have a model, f, where Y=f(X) X is an n x m matrix of samples from m parameters ...
David LeBauer's user avatar
0 votes
2 answers
2k views

evaluate (i.e., predict) a smoothing spline outside R

I fitted a smoothing spline to data in R with library(splines) Model <- smooth.spline(x, y, df =6) I would like to take the fitted spline and evaluate it for arbitrary new data in an external ...
DeltaIV's user avatar
  • 5,415
22 votes
4 answers
55k views

Are there any good libraries for solving cubic splines in C++? [closed]

I'm looking for a good C++ library to give me functions to solve for large cubic splines (on the order of 1000 points) anyone know one?
Faken's user avatar
  • 11.6k
36 votes
8 answers
143k views

How to perform cubic spline interpolation in python?

I have two lists to describe the function y(x): x = [0,1,2,3,4,5] y = [12,14,22,39,58,77] I would like to perform cubic spline interpolation so that given some value u in the domain of x, e.g. u = ...
user112829's user avatar
19 votes
4 answers
14k views

Find minimum distance from point to complicated curve

I have a complicated curve defined as a set of points in a table like so (the full table is here): # x y 1.0577 12.0914 1.0501 11.9946 1.0465 11.9338 ... If I plot this table with the commands:...
Gabriel's user avatar
  • 41.8k
14 votes
3 answers
74k views

Spline Interpolation with Python

I wrote the following code to perform a spline interpolation: import numpy as np import scipy as sp x1 = [1., 0.88, 0.67, 0.50, 0.35, 0.27, 0.18, 0.11, 0.08, 0.04, 0.04, 0.02] y1 = [0., 13....
Hellfish's user avatar
  • 1,695
12 votes
3 answers
11k views

How to make monotonic (increasing) smooth spline with smooth.spline() function?

I have data that are strictly increasing and would like to fit a smoothing spline that is monotonically increasing as well with the smooth.spline() function if possible, due to the ease of use of this ...
Michael Clinton's user avatar
11 votes
2 answers
13k views

How to interpret lm() coefficient estimates when using bs() function for splines

I'm using a set of points which go from (-5,5) to (0,0) and (5,5) in a "symmetric V-shape". I'm fitting a model with lm() and the bs() function to fit a "V-shape" spline: lm(formula = y ~ bs(x, ...
PDG's user avatar
  • 287
11 votes
4 answers
28k views

Is there easy way in python to extrapolate data points to the future?

I have a simple numpy array, for every date there is a data point. Something like this: >>> import numpy as np >>> from datetime import date >>> from datetime import date &...
maplpro's user avatar
  • 356
10 votes
2 answers
13k views

Akima interpolation of an array of doubles

Assuming I have an array of doubles, what's a good algorithm to sample this series using Akima interpolation? I'm too stupid to translate that mathematical description into code. // values is an ...
David Rutten's user avatar
  • 4,776
5 votes
3 answers
1k views

How to use the lambda argument of smooth.spline in RPy WITHOUT Python interprating it as lambda

I want to use the natural cubic smoothing splines smooth.spline from R in Python (like som many others want as well (Python natural smoothing splines, Is there a Python equivalent to the smooth.spline ...
Jakob's user avatar
  • 1,113
5 votes
3 answers
11k views

Catmull-Rom splines in python

Is there a library or function in python to compute Catmull-Rom spline from three points ? What I need in the end are the x,y coordinates of points along the spline, provided that they are always ...
Stefano Borini's user avatar
4 votes
1 answer
4k views

Construct a symbolic interpolating spline through given points using SymPy

Pretend I start with some simple dataset which is defined on R2 follows: DataPointsDomain = [0,1,2,3,4,5] DataPointsRange = [3,6,5,7,9,1] With scipy I can make a lazy polynomial spline using the ...
D A's user avatar
  • 3,308
4 votes
2 answers
5k views

Emulating Excel's "scatter with smooth curve" spline function in Matplotlib for 3 points

I'm trying to emulate Excel's Insert>Scatter>Scatter with smooth lines and markers command in Matplotlib The scipy function interpolate creates a similar effect, with some nice examples of how to ...
Dave's user avatar
  • 525
2 votes
1 answer
2k views

Shape Transformers and Interfaces OpenCV3.0

I was trying to make use of the new Shape Transformers and Interfaces of OpenCV3.0. Unfortunately it doesn't work as expected. To ensure not making any fancy warps and getting strange results cause of ...
Ives's user avatar
  • 49
2 votes
1 answer
2k views

What algorithm used in interp1d function in scipy.interpolate

So i was writing a python program for my numerical course, and I had to code a cubic spline program. So i implement the formula for cubic spline given in books like Numerical methods by Chapra and ...
Eular's user avatar
  • 1,757
21 votes
5 answers
25k views

Splines with Python (using control knots and endpoints)

I'm trying to do something like the following (image extracted from wikipedia) #!/usr/bin/env python from scipy import interpolate import numpy as np import matplotlib.pyplot as plt # sampling x = ...
silgon's user avatar
  • 7,053
19 votes
2 answers
28k views

How can I use spline() with ggplot?

I would like to fit my data using spline(y~x) but all of the examples that I can find use a spline with smoothing, e.g. lm(y~ns(x), df=_). I want to use spline() specifically because I am using ...
David LeBauer's user avatar
18 votes
3 answers
5k views

Spline with constraints at border

I have measured data on a three dimensional grid, e.g. f(x, y, t). I want to interpolate and smooth this data in the direction of t with splines. Currently, I do this with scipy.interpolate....
Dux's user avatar
  • 1,226