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

In mathematics, 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 (which are known as knots).

A quadratic spline composed of six polynomial segments

(Source text & picture: wikipedia)

A spline can be used for either or .

1164 questions
172
votes
14 answers

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 gathered points? I've googled but I have only…
Homan
  • 25,618
  • 22
  • 70
  • 107
52
votes
6 answers

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
  • 1,695
  • 1
  • 16
  • 22
48
votes
5 answers

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 what is available to implement it yourself? By…
Niko Föhr
  • 28,336
  • 10
  • 93
  • 96
33
votes
8 answers

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 = 1.25 I can find y(u). I found this in SciPy but I…
user112829
  • 491
  • 1
  • 4
  • 7
31
votes
7 answers

Curve fitting unsorted points on a plane

Question: How do you fit a curve to points on a plane if they aren't single valued? For the example shown, how would one fit a curve (like the black one) to the noisy blue data? It's similar to spline smoothing, but I don't know the order of the…
tkw954
  • 940
  • 2
  • 10
  • 16
31
votes
6 answers

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 inherent ambiguities in the smoothing process, so…
thund
  • 1,842
  • 2
  • 21
  • 31
24
votes
8 answers

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

I'd like to implement a Bézier curve. I've done this in C# before, but I'm totally unfamiliar with the C++ libraries. How should I go about creating a quadratic curve? void printQuadCurve(float delta, Vector2f p0, Vector2f p1, Vector2f p2); Clearly…
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
23
votes
1 answer

Finding curvature from a noisy set of data points using 2d/3dsplines? (C++)

I am trying to extract the curvature of a pulse along its profile (see the picture below). The pulse is calculated on a grid of length and height: 150 x 100 cells by using Finite Differences, implemented in C++. I extracted all the points with the…
JannaJ
  • 251
  • 2
  • 6
22
votes
4 answers

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). How can I find an acceptable set of…
janesconference
  • 6,333
  • 8
  • 55
  • 73
22
votes
4 answers

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

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
  • 11,352
  • 17
  • 59
  • 74
20
votes
5 answers

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 = np.linspace(0, 10, 10) y = np.sin(x) # spline…
silgon
  • 6,890
  • 7
  • 46
  • 67
20
votes
2 answers

How do I use splines in pythonOCC?

I have a two-part question about how to use splines in pythonOCC. Firstly, I know that I can create a spline with array = [] array.append(gp_Pnt2d (0,0)) array.append(gp_Pnt2d (1,2)) array.append(gp_Pnt2d (2,3)) array.append(gp_Pnt2d…
Steenstrup
  • 644
  • 6
  • 15
19
votes
2 answers

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 this to do the analysis represented by the plot that…
David LeBauer
  • 31,011
  • 31
  • 115
  • 189
19
votes
1 answer

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 where are the knots that the spline used? Thanks!
memy
  • 229
  • 1
  • 2
  • 8
19
votes
4 answers

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: plt.plot(x_data, y_data,…
Gabriel
  • 40,504
  • 73
  • 230
  • 404
1
2 3
77 78