Skip to content
FutureBlitz

    Install

    Import std.math.curves

    Curve2

    std.math.curves

    class

    Public Class Curve2

    A curve in 2D from a Function of t from 0 to 1, which it goes along by length too, from a table of samples' lengths, its straight lines' between them, so more samples follow its bends closer.

    Examples

    
    Local road = Curve2.CatmullRom([Vec2(0, 0), Vec2(10, 0), Vec2(20, 0)])
    Expect(IsClose(road.Length, 20, 0.01))
    Expect(IsClose(road.PointAtDistance(5), Vec2(5, 0), 0.01))
    Expect(road.Sample(5).Count == 5)

    std/math/curves.fb, line 213

    • @PanicsAtCaller Public New(point: Func(Float): Vec2, samples: Int = 256) constructor #

      The curve point gives for t from 0 to 1, measured at samples places along it. Fewer than one sample panics.

    • @PanicsAtCaller Public Static Method CatmullRom(points: Vec2[], closed: Bool = False, samples: Int = 64): Curve2 static method #

      The Catmull-Rom spline through the points, each of them on it, around to the first when closed, measured at samples places along each segment. Fewer than two points, or than one sample, panics.

    • @PanicsAtCaller Public Static Method BSpline(points: Vec2[], closed: Bool = False, samples: Int = 64): Curve2 static method #

      The uniform cubic B-spline the points shape, near them rather than through them: an open one starts and ends at its ends, and a closed one goes around. It's measured at samples places along each segment. Fewer than two points, or than one sample, panics.

    • @PanicsAtCaller Public Static Method Bezier(points: Vec2[], samples: Int = 64): Curve2 static method #

      The cubic Beziers one after another, each from the last one's end: a start, then two control points and an end for each, so 3n + 1 points in all, measured at samples places along each. Any other count of points, or fewer than one sample, panics.

    • Public Property Length: Float property #

      How long the curve is, as its samples measure it.

    • @PanicsAtCaller Public Method PointAt(t: Float): Vec2 method #

      The point the curve's Function gives for t, kept from 0 to 1. A NaN t panics.

    • @PanicsAtCaller Public Method PointAtDistance(distance: Float): Vec2 method #

      The point so far along the curve, kept from 0 to its Length. A NaN distance panics.

    • @PanicsAtCaller Public Method Sample(count: Int): Vec2[] method #

      count points along the curve the same distance apart, from its start to its end. Fewer than two panics.

    Report an issue with this page or with FutureBlitz on GitHub.