# Bilinear spline interpolation

Bilinear spline is a fast (although less precise than bicubic spline) two-dimensional interpolation method. ALGLIB package contains an implementation of 2D splines available in several programming languages:

• , a high performance C++ library with great portability across hardware and software platforms
• , a highly optimized C# library with two alternative backends: a pure C# implementation (100% managed code) and a high-performance native implementation (Windows, Linux) with same C# interface

Our implementation of 2D splines:

• supports bilinear and bicubic splines
• supports operations like interpolation, differentiation, linear transformation, serialization
• allows you to fit bicubic splines to large-scale datasets (with up to 100M points)

# Getting started and examples

## Getting started

Bilinear spline interpolation functionality is provided by the spline2d subpackage of ALGLIB package. A bilinear spline can be created from the data sampled at the regular grid (to be exact, more general rectilinear one) with spline2dbuildbilinearv function. This function supports both scalar and vector-valued splines.

After an instance of spline object is built, you can perform following operations:

• evaluate spline with spline2dcalc (for a scalar spline) or spline2dcalcv, spline2dcalcvbuf and spline2dcalcvi (for a vector-valued spline) functions
• evaluate spline derivative with spline2ddiff and spline2ddiffvi (for a vector-valued spline) functions
• perform linear transformation of the spline by means of spline2dlintransf and spline2dlintransxy functions
• serialize/unserialize it with spline2dserialize and spline2dunserialize functions

## Examples

ALGLIB Reference Manual includes following examples which show how to work with bilinear splines:

• spline2d_bilinear - spline creation and basic operations
• spline2d_copytrans - linear transformation
• spline2d_unpack - unpacking spline coefficients
• spline2d_vector - working with vector-valued splines

# Comparison with bicubic splines

Bilinear spline is a fast and compact method for interpolation of 2D data. For the same amount of input data it needs 4x less memory than bicubic spline. Spline calculation/evaluation is an order of magnitude faster than that of bicubic splines.

From the other side, following drawbacks can be noted:

1. bilinear spline has nonsmooth first derivative; it has a discontinuity at the boundary between spline "cells"
2. precision of bilinear splines is typically less than that of bicubic ones

Thus, unless you have really tight memory and performance constraints, we recommend you to use bicubic splines in your work.

# Fitting 2D splines to scattered data

Although internally all 2D splines use a rectilinear grid as the basis, it is possible to fit a spline to scattered (irregular) data with least squares solver.

ALGLIB has two high-performance algorithms which can do so. However, because of inherent non-smoothness and low precision of bilinear splines, these algorithms fit only bicubic splines. See corresponding part of the article on bicubic splines for more information.

ALGLIB Project offers you two editions of ALGLIB:

ALGLIB Free Edition:
offers full set of numerical functionality
extensive algorithmic optimizations
no low level optimizations

ALGLIB Commercial Edition:
flexible pricing
offers full set of numerical functionality
extensive algorithmic optimizations
high performance (SMP, SIMD)

## ALGLIB 3.15.0 for C++

C++ library.
Delivered with sources.
Monolithic design.
Extreme portability.
Editions:   FREE   COMMERCIAL

## ALGLIB 3.15.0 for C#

C# library with native kernels.
Delivered with sources.
VB.NET and IronPython wrappers.
Extreme portability.
Editions:   FREE   COMMERCIAL

## ALGLIB 3.15.0 for Delphi

Delphi wrapper around C core.
Delivered as precompiled binary.
Compatible with FreePascal.
Editions:   FREE   COMMERCIAL

## ALGLIB 3.15.0 for CPython

CPython wrapper around C core.
Delivered as precompiled binary.
Editions:   FREE   COMMERCIAL