generative-art-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Geometry.Trajectory

Synopsis

Various

pointOnTrajectory :: Sequential list => list Vec2 -> Double -> Vec2 Source #

Walk a certain Distance on a trajectory defined by its points.

This caches the internal LUT when partially applied, so that the following will only compute it once for repeated lookups:

let goto = pointOnTrajectory […]
print [goto d | d <- [0, 0.1 .. 5]]

reassembleLines Source #

Arguments

:: (Ord point, Foldable f) 
=> (line -> (point, point))

How to extract two neighbouring points from the data given

-> f line

Collection of neighbouring points

-> [[point]]

List of trajectories consisting of points

Given a collection of lines that fit together back-to-back (as in ==), reassemble them to extract the underlying points in order. This works even for collections of multiple cut-up trajectories, as long as they do not share any points.

In a way, this can be seen as the inverse of pairing up points to line segments,

reassembleLines (zipWith Line xs (tail xs)) == xs

Unsafety warning: This algorithm wasn’t tested for cases when multiple trajectories share points. I have no idea what happens in that case, but certainly nothing useful.

Path simplifiers

simplifyTrajectoryRdp Source #

Arguments

:: Sequential vector 
=> Double

Discard points closer than \(\varepsilon\) to the connecting line of two points. Larger values yield simpler results.

-> vector Vec2

Trajectory

-> Vector Vec2

Simplified trajectory

Simplify a path by dropping unnecessary points, using the the Ramer-Douglas-Peucker algorithm. The larger the tolerance distance, the simpler the result will be.

This is very useful in conjunction with bezierSmoothen: first drop the redundancies, then smoothen using Bezier curves again, to yield a result visually similar to the original data, but with a much smaller data footprint (SVGs can become huge!).

If your trajectory contains more than just the points you want to simplify on, use simplifyTrajectoryRdpBy.

simplifyTrajectoryRdpBy Source #

Arguments

:: Sequential vector 
=> Double

Discard points closer than \(\varepsilon\) to the connecting line of two points. Larger values yield simpler results.

-> (a -> Vec2)

Extract the relevant Vec2 to simplify on

-> vector a

Trajectory

-> Vector a

Simplified trajectory

simplifyTrajectoryRdp, but allows specifying a function for how to extract the points to base simplifying on from the input.

This is useful when your trajectory contains metadata, such as the velocity at each point.

simplifyTrajectoryVW Source #

Arguments

:: Sequential vector 
=> Double

Cutoff parameter. We remove points that span triangles smaller than this. Larger values yield simpler results.

-> vector Vec2

Trajectory

-> Vector Vec2

Simplified trajectory

Simplify a path by dropping unnecessary points using the the Visvalingam-Whyatt algorithm. The larger the cutoff parameter, the simpler the result will be.

This is very useful in conjunction with bezierSmoothen: first drop the redundancies, then smoothen using Bezier curves again, to yield a result visually similar to the original data, but with a much smaller data footprint (SVGs can become huge!).

If your trajectory contains more than just the points you want to simplify on, use simplifyTrajectoryVWBy.

simplifyTrajectoryVWBy Source #

Arguments

:: (Ord a, Sequential vector) 
=> Double

Cutoff parameter. We remove points that span triangles smaller than this. Larger values yield simpler results.

-> (a -> Vec2)

Extract the relevant Vec2 to simplify on

-> vector a

Trajectory

-> Vector a

Simplified trajectory

simplifyTrajectoryVWBy, but allows specifying a function for how to extract the points to base simplifying on from the input.

This is useful when your trajectory contains metadata, such as the velocity at each point.

simplifyTrajectoryRadial Source #

Arguments

:: Sequential vector 
=> Double

Cutoff parameter: minimum distance to the next neighbour. Higher values yield fewer points.

-> vector Vec2

Trajectory

-> [Vec2]

Simplified trajectory

Simplify a path by dropping points too close to their neighbours. The larger the cutoff parameter, the simpler the result will be.

simplifyTrajectoryRadialBy Source #

Arguments

:: Sequential vector 
=> Double

Cutoff parameter: minimum distance to the next neighbour. Higher values yield fewer points.

-> (a -> Vec2)

Extract the relevant Vec2 to simplify on

-> vector a

Trajectory

-> [a]

Simplified trajectory

simplifyTrajectoryRadial, but allows specifying a function for how to extract the points to base simplifying on from the input.