curves Module

This module defines a type curve_t that represents a parametric curve in nD space.

The curve is defined by a sequence of points and a method for interpolation. The interpolation method is specified by the user when creating the curve. The default method is ‘pchip’ (piecewise cubic Hermite interpolating polynomial).


Uses


Interfaces

public interface curve_t

Create a new curve from a sequence of points.

  • private function new_curve(points, method, extrap) result(c)

    Create a new curve from a sequence of points.

    The curve is given by a sequence of points in nD space, interpolation method, and extrapolation setup. Supported interpolation methods are

    • linear for piecewise linear interpolation (i.e. polyline)
    • pchip for piecewise cubic Hermite interpolating polynomial (default)

    Supported extrapolation methods are

    • extrap for linear extrapolation (default)
    • NaN for NaN extrapolation

    Arguments

    Type IntentOptional Attributes Name
    real(kind=rkind), intent(in) :: points(:,:)

    The points that define the curve

    character(len=*), intent(in), optional :: method

    The interpolation method,

    character(len=*), intent(in), optional :: extrap

    Return Value type(curve_t)


Derived Types

type, public ::  curve_t

A parametric curve in nD space.

Components

Type Visibility Attributes Name Initial
real(kind=rkind), public :: begin

The beginning of parameter span

real(kind=rkind), public :: end

The end of parameter span

character(len=:), public, allocatable :: extrap

The extrapolation method

real(kind=rkind), public, allocatable :: knots(:)

The parameter values for the points

character(len=:), public, allocatable :: method

The interpolation method

real(kind=rkind), public, allocatable :: points(:,:)

The points that define the curve

Constructor

Create a new curve from a sequence of points.

private function new_curve (points, method, extrap)

Create a new curve from a sequence of points.

The curve is given by a sequence of points in nD space, interpolation method, and extrapolation setup. Supported interpolation methods are

  • linear for piecewise linear interpolation (i.e. polyline)
  • pchip for piecewise cubic Hermite interpolating polynomial (default)

Supported extrapolation methods are

  • extrap for linear extrapolation (default)
  • NaN for NaN extrapolation

Type-Bound Procedures

generic, public :: at => at_1, at_n

Evaluate the curve at a single point or at multiple points

procedure, public :: move_by

Move the curve by a given displacement

procedure, public :: tangent_at

Compute the tangent vector at a given point


Functions

public function intersection(c1, c2, x0) result(x)

Compute the intersection of two curves.

Arguments

Type IntentOptional Attributes Name
type(curve_t), intent(in) :: c1

The first curve

type(curve_t), intent(in) :: c2

The second curve

real(kind=rkind), intent(in), optional :: x0(:)

The initial guess for the intersection

Return Value real(kind=rkind), allocatable, (:)

The intersection point


Subroutines

public subroutine project_to_curve(x, c, t, t0)

Project a point onto a curve.

Arguments

Type IntentOptional Attributes Name
real(kind=rkind), intent(inout) :: x(:)

The point to be projected

type(curve_t), intent(in) :: c

The curve

real(kind=rkind), intent(out), optional :: t

The parameter value of the projection

real(kind=rkind), intent(in), optional :: t0

The initial guess for the parameter of the projection