# Unit CastleCurves

## Description

3D curves (TCurve and basic descendants).

## Overview

### Classes, Interfaces, Objects and Records

Name Description
Class `ECurveFileInvalid`
Class `TCurve` 3D curve, a set of points defined by a continuous function Point for arguments within [TBegin, TEnd].
Class `TCurveList`
Class `TCasScriptCurve` Curve defined by explicitly giving functions for Point(t) = x(t), y(t), z(t) as CastleScript expressions.
Class `TControlPointsCurve` A basic abstract class for curves determined my some set of ControlPoints.
Class `TPiecewiseCubicBezier` Piecewise (composite) cubic Bezier curve.

### Functions and Procedures

 `function CubicBezier1D(T: Single; const Points: TVector4): Single;` `function CubicBezier2D(T: Single; const Points: TCubicBezier2DPoints): TVector2;` `function CubicBezier3D(T: Single; const Points: TCubicBezier3DPoints): TVector3;` `function CatmullRomSpline(const X: Single; const Loop: boolean; const Arguments: TSingleList; const Values: TSingleList): Single;` `function CatmullRom(const V0, V1, V2, V3, X: Single): Single;` `function HermiteSpline(const X: Single; const Loop: boolean; const Arguments, Values, Tangents: TSingleList): Single;` `function HermiteTenseSpline(const X: Single; const Loop: boolean; const Arguments, Values: TSingleList): Single;`

### Types

 `TControlPointsCurveClass = class of TControlPointsCurve;` `TControlPointsCurveList = specialize TObjectList;` `TCubicBezier2DPoints = array [0..3] of TVector2;` `TCubicBezier3DPoints = array [0..3] of TVector3;`

## Description

### Functions and Procedures

 `function CubicBezier1D(T: Single; const Points: TVector4): Single;` Cubic (4 control points) Bezier curve (with all weights equal) in 1D.
 `function CubicBezier2D(T: Single; const Points: TCubicBezier2DPoints): TVector2;` Cubic (4 control points) Bezier curve (with all weights equal) in 2D.
 `function CubicBezier3D(T: Single; const Points: TCubicBezier3DPoints): TVector3;` Cubic (4 control points) Bezier curve (with all weights equal) in 3D.
 `function CatmullRomSpline(const X: Single; const Loop: boolean; const Arguments: TSingleList; const Values: TSingleList): Single;` Catmull-Rom spline. Nice way to have a function that for certain arguments reaches certain values, and between interpolates smoothly. Catmull-Rom splines are a special case of cubic Hermite splines, see https://en.wikipedia.org/wiki/Cubic_Hermite_spline .
`function CatmullRom(const V0, V1, V2, V3, X: Single): Single;`

Catmull-Rom spline low-level function. For X in [0..1], the curve values change from V1 to V2. V0 and V3 are curve values outside the [0..1] range, used to calculate tangents.

 `function HermiteSpline(const X: Single; const Loop: boolean; const Arguments, Values, Tangents: TSingleList): Single;` Hermite spline. Nice way to have a function that for certain arguments reaches certain values, and between interpolates smoothly. Requires specifying tangent values (use CatmullRomSpline or HermiteTenseSpline to use automatic tangents).
 `function HermiteTenseSpline(const X: Single; const Loop: boolean; const Arguments, Values: TSingleList): Single;` Hermite spline with tangents zero (it will be horizontal at control points). Nice way to have a function that for certain arguments reaches certain values, and between interpolates smoothly. This is equivalent (for faster) to using HermiteSpline with all tangents equal to zero. This is called a "cardinal spline", a special case of Hermite spline, with all tangents calculated with "tension" parameter equal to 1 (maximum), which means that all tangents are simply zero (horizontal). See https://en.wikipedia.org/wiki/Cubic_Hermite_spline for math behind this.
 `TControlPointsCurveClass = class of TControlPointsCurve;`
 `TControlPointsCurveList = specialize TObjectList;`
 `TCubicBezier2DPoints = array [0..3] of TVector2;`
 `TCubicBezier3DPoints = array [0..3] of TVector3;`