hobbyCurve

fun ShapeContour.hobbyCurve(curl: Double = 0.0, tension: Double = 1.0, atLeast: Boolean = false): ShapeContour(source)

Replaces this contour by a Hobby curve through its vertices, see hobbyCurve.

Parameters

curl

the curl at the ends of an open contour

tension

the METAFONT tension at every point, at least 3/4; higher values give tighter curves

atLeast

whether the tension is a minimum that keeps every segment inside the triangle of its chord and end tangents, as METAFONT's tension atleast


fun Shape.hobbyCurve(curl: Double = 0.0, tension: Double = 1.0, atLeast: Boolean = false): Shape(source)

Replaces every contour of this shape by a Hobby curve through its vertices, see ShapeContour.hobbyCurve.


fun hobbyCurve(points: List<Vector2>, closed: Boolean = false, curl: Double = 0.0, tensions: (chordIndex: Int, inAngleDegrees: Double, outAngleDegrees: Double) -> Pair<Double, Double> = { _, _, _ -> Pair(1.0, 1.0) }): ShapeContour(source)

Generates a smooth contour passing through a set of points based on Hobby's algorithm.

Return

A ShapeContour object representing the smoothed curve based on Hobby's algorithm.

Parameters

points

A list of 2D points through which the curve should pass.

closed

A boolean value indicating whether the curve is closed (true) forming a loop, or open (false). The default is false.

curl

A parameter that controls the curvature of the open-ended curve. Only applicable if the curve is not closed. The default is 0.0.

tensions

A lambda function that accepts the chord index (an integer) and returns a pair of factors (Double) for the lengths of the curve's control handles, applied after the curve has been solved. Larger values give rounder segments. These are not METAFONT tensions, which enter the solve itself and make the curve tighter as they grow; see the overloads that take a tension for those. The default lambda assigns both values as 1.0.


fun hobbyCurve(points: List<Vector2>, closed: Boolean = false, curl: Double = 0.0, tension: Double, atLeast: Boolean = false): ShapeContour(source)

Generates a Hobby curve through points with a METAFONT tension, after Hobby, "Smooth, easy to compute interpolating splines" (Discrete & Computational Geometry, 1986) and Knuth, "METAFONT: The Program" (§276-§299).

The tension enters the equations for the directions at the points, not only the lengths of the control handles: with reciprocal tensions α where a segment leaves a point and β where it arrives, the mock curvature at an interior point is continuous where A·θᵢ₋₁ + (B + C)·θᵢ + D·θᵢ₊₁ = -B·ψᵢ - D·ψᵢ₊₁, with A = αᵢ₋₁ / (βᵢ²·dᵢ₋₁), B = (3 - αᵢ₋₁) / (βᵢ²·dᵢ₋₁), C = (3 - βᵢ₊₁) / (αᵢ²·dᵢ) and D = βᵢ₊₁ / (αᵢ²·dᵢ), for the directions θ relative to the chords, the turning angles ψ and the chord lengths d. The ends of an open curve follow from the curl through METAFONT's curl ratio. The control handles have length ρ(θ, φ) / (3τ) times the chord. Tension 1 is Hobby's original curve, higher tensions give tighter curves that approach the polyline, and tensions below 1, down to 3/4, rounder ones.

With atLeast the tension is a minimum, as METAFONT's tension atleast: where the tangents at both ends of a segment lie on the same side of its chord, its handles are shortened so that the segment stays inside the triangle of the chord and the two tangent lines.

Parameters

points

the points through which the curve passes

closed

whether the curve is closed

curl

the curl at the ends of an open curve: 0 makes the end segments straighten out, 1 makes them nearly circular arcs

tension

the tension at every point, at least 3/4

atLeast

whether the tension is a minimum that keeps every segment inside the triangle of its chord and end tangents


fun hobbyCurve(points: List<Vector2>, closed: Boolean = false, curl: Double = 0.0, segmentTensions: List<HobbyTension>): ShapeContour(source)

Generates a Hobby curve through points with METAFONT tensions per segment, see the overload that takes a single tension.

Parameters

segmentTensions

the tensions of every segment, one per segment: as many as there are points for a closed curve, one fewer for an open one


fun hobbyCurve(points: List<Vector3>, closed: Boolean = false, curl: Double = 0.0, tensions: (chordIndex: Int, inAngleDegrees: Double, outAngleDegrees: Double) -> Pair<Double, Double> = { _, _, _ -> Pair(1.0, 1.0) }): Path3D(source)

Uses Hobby's algorithm to construct a Path3D through a given list of points.

Return

A Path3D through points.

Parameters

points

The list of points through which the curve should go.

closed

Whether to construct a closed or open curve.

curl

The 'curl' at the endpoints of the curve; this is only applicable when closed is false. Best results for values in -1, 1, where a higher value makes segments closer to circular arcs.

tensions

A function that returns factors for the lengths of the in and out control handles given a chord index, applied after the curve has been solved; these are not METAFONT tensions, see the overloads that take those.


fun hobbyCurve(points: List<Vector3>, closed: Boolean = false, curl: Double = 0.0, tension: Double, atLeast: Boolean = false): Path3D(source)

A 3D Hobby curve through points with a METAFONT tension, see the 2D overload that takes a single tension.


fun hobbyCurve(points: List<Vector3>, closed: Boolean = false, curl: Double = 0.0, segmentTensions: List<HobbyTension>): Path3D(source)

A 3D Hobby curve through points with METAFONT tensions per segment, see the 2D overload.