Gin
Loading...
Searching...
No Matches
Spline Class Reference

Cubic spline interpolation for smooth curves through discrete data points. More...

#include <gin_spline.h>

Classes

class  Element

Public Member Functions

 Spline (const juce::Array< Point< double > > &points)
double operator[] (double x) const
double interpolate (double x) const

Detailed Description

Cubic spline interpolation for smooth curves through discrete data points.

Spline provides cubic spline interpolation, creating a smooth curve that passes through all given data points. Unlike linear interpolation, cubic splines have continuous first and second derivatives (C1 and C2 continuity), resulting in very smooth, natural-looking curves.

Cubic spline interpolation is ideal for:

  • Smooth animation curves
  • Data visualization and smoothing
  • Upsampling discrete data
  • Creating smooth parameter transitions
  • Generating lookup tables

Key Features:

  • C1 and C2 continuity (smooth first and second derivatives)
  • Passes exactly through all input points
  • Efficient evaluation using piecewise cubic polynomials
  • Natural boundary conditions
  • Operator[] syntax for convenient evaluation

Important: Points must be added in increasing x order.

Usage:

juce::Array<Point<double>> points;
points.add({0.0, 0.0});
points.add({1.0, 2.5});
points.add({2.0, 1.8});
points.add({3.0, 4.0});
points.add({4.0, 3.2});
Spline spline(points);
// Interpolate at any x position
double y1 = spline[1.5]; // Using operator[]
double y2 = spline.interpolate(2.7); // Using interpolate()
// Evaluate many points for smooth curve
for (double x = 0.0; x <= 4.0; x += 0.1)
{
double y = spline[x];
// ... use interpolated value
}
Spline(const juce::Array< Point< double > > &points)

Based on implementation by Devin Lane: https://shiftedbits.org/2011/01/30/cubic-spline-interpolation/

See also
Integrator, LeastSquaresRegression

Constructor & Destructor Documentation

◆ Spline()

Spline::Spline ( const juce::Array< Point< double > > & points)

Member Function Documentation

◆ operator[]()

double Spline::operator[] ( double x) const

◆ interpolate()

double Spline::interpolate ( double x) const

The documentation for this class was generated from the following file: