Copyright | (c) 2011 diagrams-lib team (see LICENSE) |
---|---|

License | BSD-style (see LICENSE) |

Maintainer | diagrams-discuss@googlegroups.com |

Safe Haskell | None |

Language | Haskell2010 |

A *cubic spline* is a smooth, connected sequence of cubic curves.
This module provides two methods for constructing splines.

The `cubicSpline`

method can be used to create closed or open cubic
splines from a list of points. The resulting splines *pass through*
all the control points, but depend on the control points in a
"global" way (that is, changing one control point may alter the
entire curve). For access to the internals of the spline
generation algorithm, see Diagrams.CubicSpline.Internal.

`bspline`

creates a cubic B-spline, which starts and ends at the
first and last control points, but does not necessarily pass
through any of the other control points. It depends on the control
points in a "local" way, that is, changing one control point will
only affect a local portion of the curve near that control point.

# Constructing paths from cubic splines

cubicSpline :: (V t ~ v, N t ~ n, TrailLike t, Fractional (v n)) => Bool -> [Point v n] -> t #

Construct a spline path-like thing of cubic segments from a list of vertices, with the first vertex as the starting point. The first argument specifies whether the path should be closed.

pts = map p2 [(0,0), (2,3), (5,-2), (-4,1), (0,3)] spot = circle 0.2 # fc blue # lw none mkPath closed = position (zip pts (repeat spot)) <> cubicSpline closed pts cubicSplineEx = (mkPath False ||| strutX 2 ||| mkPath True) # centerXY # pad 1.1

For more information, see http://mathworld.wolfram.com/CubicSpline.html.

bspline :: (TrailLike t, V t ~ v, N t ~ n) => BSpline v n -> t #

Generate a uniform cubic B-spline from the given control points. The spline starts and ends at the first and last control points, and is tangent to the line to the second(-to-last) control point. It does not necessarily pass through any of the other control points.

pts = map p2 [(0,0), (2,3), (5,-2), (-4,1), (0,3)] spot = circle 0.2 # fc blue # lw none bsplineEx = mconcat [ position (zip pts (repeat spot)) , bspline pts ] # frame 0.5