Pink 0.9

curve2spline.c File Reference

converts a discrete open curve into a spline More...


Detailed Description

converts a discrete open curve into a spline

Usage: curve2spline curve.list [tolerance] out.spline

Description:

Let C be the discrete open curve described in curve.list. This program finds a approximation of C in the form of a parametric curve P defined by two (in 2D) or three (in 3D) splines such that the maximal distance between P and C is beyond the given tolerance. The default value for tolerance is 2.

The result is given in the form of the list of control points for the splines, followed by the set of coefficients for each spline segment. The file format is the following for 2D:

c n+1 (where n+1 denotes the number of control points)
x1 y1
...
xn+1 yn+1
C0X1 C0Y1 C1X1 C1Y1 C2X1 C2Y1 C3X1 C3Y1
...
C0Xn C0Yn C1Xn C1Yn C2Xn C2Yn C3Xn C3Yn

and in the 3D case:

C n+1 (where n+1 denotes the number of control points)
x1 y1 z1
...
xn+1 yn+1 zn+1
C0X1 C0Y1 C0Z1 C1X1 C1Y1 C1Z1 C2X1 C2Y1 C2Z1 C3X1 C3Y1 C3Z1
...
C0Xn C0Yn C0Zn C1Xn C1Yn C1Zn C2Xn C2Yn C2Zn C3Xn C3Yn C3Zn

The ith segment (starting with i=0) of the parametric curve P is then defined by:

x(t) = C3Xi * t^3 + C2Xi * t^2 + C1Xi * t + C0Xi
y(t) = C3Yi * t^3 + C2Yi * t^2 + C1Yi * t + C0Yi
z(t) = C3Zi * t^3 + C2Zi * t^2 + C1Zi * t + C0Zi
with t in [i,i+1]

Warning:
Closed curves are not allowed.

Reference:
[Cou10] M. Couprie: "Short note on natural cubic splines and discrete curves", internal report, 2010.

Types supported: list 2D, list 3D

Category: draw geo

Author:
Michel Couprie