Worms #
This file defines worms as piecewise linear paths of unit length.
Approximate sqrt(s) using Newton's method (Babylonian method). Given s ≥ 0 and epsilon > 0, returns a rational r such that |r - sqrt(s)| < epsilon
Equations
- Moser.sqrtApprox s epsilon fuel = if s ≤ 0 then 0 else Moser.sqrtApprox.newton s epsilon (max 1 s) fuel
Instances For
One step of the Newton iteration on x, recursing up to n more times.
Equations
Instances For
Approximate the Euclidean distance between two points to within epsilon. Returns a rational d such that |d - dist(p,q)| < epsilon
Equations
- Moser.distanceApprox p q epsilon = Moser.sqrtApprox (p.distSq q) epsilon
Instances For
Compute an approximate total length of a path given by vertices
Equations
- One or more equations did not get rendered due to their size.
Instances For
A worm is a piecewise linear path (at least 2 vertices)
- vertices : List RationalPoint
The vertices defining the path
The path has at least 2 vertices
Instances For
Scale a point by a rational factor
Instances For
Get the approximate total length of the worm
Equations
- w.lengthApprox epsilon = Moser.totalLengthApprox w.vertices epsilon
Instances For
Scale a worm to have approximately unit length. Returns the scaled worm. The scaling factor is 1/length.
Equations
- w.scaleToUnit epsilon = if w.lengthApprox epsilon ≤ 0 then w else w.scale (1 / w.lengthApprox epsilon)
Instances For
Get the convex hull as a ConvexPolygon
Equations
Instances For
Get the vertices of a unit worm
Instances For
Convert to a convex polygon
Equations
Instances For
Convert a worm to a unit worm by scaling to unit length. The epsilon parameter controls the precision of the length computation.
Equations
- w.toUnitWorm epsilon = sorry