Gin
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
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:

Key Features:

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
}
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25
Cubic spline interpolation for smooth curves through discrete data points.
Definition gin_spline.h:67

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: