splines/catmull_rom

Centripetal Catmull-Rom splines

Catmull-Rom splines are useful for paths of objects because they preserve velocity through points on the path and ensure that all points are passed through with exception of the first and last. This implementation uses the “centripetal” formulation that requires 4 control points, with the curve spanning the two central points.

Types

A centripetal Catmull-Rom spline over a generic domain. See new_2d and new_3d to construct one.

pub type CatmullRom(a) {
  CatmullRom(
    points: vec4.Vec4(a),
    scale: fn(a, Float) -> a,
    sum: fn(List(a)) -> a,
  )
}

Constructors

  • CatmullRom(
      points: vec4.Vec4(a),
      scale: fn(a, Float) -> a,
      sum: fn(List(a)) -> a,
    )

Values

pub fn new_2d(
  p0: vec2.Vec2(Float),
  p1: vec2.Vec2(Float),
  p2: vec2.Vec2(Float),
  p3: vec2.Vec2(Float),
) -> CatmullRom(vec2.Vec2(Float))

Constructs a 2d Catmull-Rom spline, given the four control-points as Vec2fs.

pub fn new_3d(
  p0: vec3.Vec3(Float),
  p1: vec3.Vec3(Float),
  p2: vec3.Vec3(Float),
  p3: vec3.Vec3(Float),
) -> CatmullRom(vec3.Vec3(Float))

Constructs a 3d Catmull-Rom spline, given the four control-points as Vec3fs.

pub fn sample(curve: CatmullRom(a), t: Float) -> a

Samples any Catmull-Rom spline at time t, where 0.0 <= t <= 1.0 (usually).

Search Document