Skip to contents

Constructs a Catmull-Rom spline interpolator given control points.

Usage

catmull_rom(control_points, closed = FALSE, alpha = 0.5)

Arguments

control_points

List of control points, where each element is a numeric vector of length 3.

closed

Logical indicating whether the spline is closed (i.e., the first and last control points are connected), defaults to false

alpha

Numeric scalar for the tension parameter, defaults to 0.5

Value

An object of class catmull_rom with methods:

  • interpolate(xi): Evaluate the interpolator at point xi.

  • prime(xi): Evaluate the derivative of the interpolator at point xi.

  • max_parameter(): Get the maximum parameter value of the spline.

  • parameter_at_point(i): Get the parameter value at index i.

Examples

control_points <- list(c(0, 0, 0), c(1, 1, 0), c(2, 0, 0), c(3, 1, 0))
interpolator <- catmull_rom(control_points)
xi <- 1.5
interpolator$interpolate(xi)
#> [1] 1.2613446 0.8307972 0.0000000
interpolator$prime(xi)
#> [1]  0.8408964 -1.1363078  0.0000000
interpolator$max_parameter()
#> [1] 3.567621
interpolator$parameter_at_point(2)
#> [1] 2.378414