Maintainer | diagrams-discuss@googlegroups.com |
---|
Generic functionality for constructing and manipulating linear or cubic Bezier segments.
- data Segment v
- straight :: v -> Segment v
- bezier3 :: v -> v -> v -> Segment v
- atParam :: (VectorSpace v, Num (Scalar v)) => Segment v -> Scalar v -> v
- segOffset :: Segment v -> v
- splitAtParam :: VectorSpace v => Segment v -> Scalar v -> (Segment v, Segment v)
- arcLength :: (InnerSpace v, Floating (Scalar v), Ord (Scalar v)) => Segment v -> Scalar v -> Scalar v
Constructing segments
The atomic constituents of paths are segments, which are single straight lines or cubic Bezier curves. Segments are translationally invariant, that is, they have no particular "location" and are unaffected by translations. They are, however, affected by other transformations such as rotations and scales.
Linear v | A linear segment with given offset. |
Cubic v v v | A cubic bezier segment specified by three offsets from the starting point to the first control point, second control point, and ending point, respectively. |
Functor Segment | |
Eq v => Eq (Segment v) | |
Ord v => Ord (Segment v) | |
Show v => Show (Segment v) | |
(InnerSpace v, OrderedField (Scalar v)) => Boundable (Segment v) | The bounding function for a segment is based at the segment's start. |
HasLinearMap v => Transformable (Segment v) | |
(Show v, HasLinearMap v) => Renderable (Segment v) ShowBackend |
straight :: v -> Segment vSource
constructs a translationally invariant linear
segment with direction and length given by the vector straight
vv
.
bezier3 :: v -> v -> v -> Segment vSource
bezier3 v1 v2 v3
constructs a translationally invariant cubic
Bezier curve where the offsets from the first endpoint to the
first and second control point and endpoint are respectively
given by v1
, v2
, and v3
.
Computing with segments
segOffset :: Segment v -> vSource
Compute the offset from the start of a segment to the
end. Note that in the case of a Bezier segment this is not the
same as the length of the curve itself; for that, see arcLength
.
splitAtParam :: VectorSpace v => Segment v -> Scalar v -> (Segment v, Segment v)Source
splitAtParam
splits a segment s
into two new segments (l,r)
at the parameter t
where l
corresponds to the portion of
s
for parameter values from 0
to t
and r
for s
from t
to 1
.
The following should hold for splitting:
paramSplit s t u | u < t = atParam s u == atParam l (u / t) | otherwise = atParam s u == atParam s t ^+^ atParam l ((u - t) / (1.0 - t)) where (l,r) = splitAtParam s t
That is to say, the parameterization scales linearly with splitting.