Learn R Programming

fdasrvf (version 2.5.0)

interparc: Interpolate Equally Spaced Points Along a Closed Curve

Description

Fits periodic cubic smoothing splines to the supplied coordinates and returns points that are equally spaced by arc length along the fitted curve. The curve is parameterized by cumulative chord length, smoothed using cyclic cubic splines (mgcv), and then reparameterized by arc length to obtain equally spaced samples.

Usage

interparc(t, ..., n.samples = 5000, k = 20, gamma = 1)

Value

A matrix with one column per coordinate dimension (V1, V2, ...), containing interpolated points that are equally spaced by arc length.

Arguments

t

Either:

  • A single integer specifying the number of equally spaced output points, or

  • A numeric vector of normalized arc-length positions between 0 and 1 at which to evaluate the curve.

...

Two or more equal-length coordinate vectors (e.g., x, y, or x, y, z) describing the input curve.

n.samples

Number of points used to approximate the arc-length parameterization of the fitted spline. Larger values improve accuracy but increase computation time.

k

Basis dimension for the cyclic cubic spline. Larger values allow more flexible fits.

gamma

Smoothing penalty multiplier passed to mgcv::gam(). Values greater than 1 produce smoother curves.

Details

The function first parameterizes the input points by cumulative chord length, fits a cyclic cubic spline to each coordinate using Restricted Maximum Likelihood (REML), estimates arc length from the fitted curve, and then evaluates the splines at parameter values corresponding to equally spaced arc-length positions.

Examples

Run this code
x <- cos(seq(0, 2*pi, length.out = 20) * 1.5 - pi/2)
y <- sin(seq(0, 2*pi, length.out = 20))
plot(x, y, type = "b")
lines(interparc(1000, x, y), col = 2)
points(interparc(10, x, y), col = 2)

Run the code above in your browser using DataLab