Library
Module
Module type
Parameter
Class
Class type
Generation and measurement of 2d bezier curve (and patch/surface) functions. Including of_path
, which produces a bezier spline function that passes through all points of the given path.
type t = float -> V2.t
A bezier curve function.
coefs ps
Compute the bezier algebraic coefficients for the control points ps
.
make ps
Create bezier function of degree n (n = List.length ps - 1
) from the control points ps
. The resulting continuous curve advances from the 0th control point at 0.
, to the final control point at 1.
.
curve ?init ?rev ?fn ?endpoint t
Draw a path of fn
segments (default = 16
) along the bezier curve t
.
init
can be provided to be prepended to (defaults to an empty list)rev
is true
, the bezier will be drawn in reverse (default = false
)endpoint
is true
, the last point will be a control point (last or first depending on rev
), otherwise it will be off by the step size (1 / fn
) (default = true
).val length :
?start_u:float ->
?end_u:float ->
?max_deflect:float ->
V2.t list ->
float
length ?start_u ?end_u ?max_deflect ps
Compute the length along the bezier defined by the control points ps
between the fractional positions start_u
and end_u
(0.
to 1.
by default). This is approximated as the sum of line segments whose midpoints deviate from the bezier by no more than max_deflect
.
patch grid
Create a bezier patch (curved surface) from an rectangular grid
of control points.
patch_curve ?fn p
Sample a grid of fn
by fn
segments describing a curved surface from the bezier patch p
. (default fn = 16
).
of_bezpath ?n ps
Create a bezier function from a series of degree n
beziers connected end-to-end defined by the control points ps
. The end-point of the first curve is the start-point of the next, and so on. Thus, two cubic-beziers (n = 3
, the default) in series is described by seven control points (middle point is shared). The number of curves is List.length ps - 1 / n
, if ps
cannot be broken by degree n
in this way, an Invalid_argument
exception will be raised.
val bezpath_of_path :
?closed:bool ->
?size:
[ `Abs of float list
| `Rel of float list
| `Flat of [ `Abs of float | `Rel of float ]
| `Mix of [ `Abs of float | `Rel of float ] list ] ->
?tangents:[ `NonUniform | `Uniform | `Tangents of V2.t list ] ->
V2.t list ->
V2.t list
bezpath_of_path ?closed ?uniform ?size ?tangents path
Create a bezier path (see of_bezpath
) which defines a curve that passes through the points of path
.
size
sets the absolute or relative (as a fraction of segment length) distance that the computed curve can deviate from the input path
. Provided either as a flat value for all points, or a list with a value for each segment of the path
(default = `Flat (`Rel 0.1)
).tangents
provides control over the tangents of the computed curve where it passes through the points of path
. Tangents can either be provided by the user with `Tangents l
, or computed `NonUniform | `Uniform
(see Path2.tangents
).closed
is true
(default = false
), an additional segment between the last and first points of path
will be included in the computations. Thus, this impacts the correct lengths of lists provided to the size
and tangents
parameters (= length of path
if closed
, one less if not).bezpath_curve ?fn ?n ps
Compute a bezier function from a series of degree n
beziers connected end-to-end defined by the control points ps
and use to draw a path of fn
segments. See of_bezpath
for explanation of bezier paths.
val of_path :
?closed:bool ->
?size:
[ `Abs of float list
| `Rel of float list
| `Flat of [ `Abs of float | `Rel of float ]
| `Mix of [ `Abs of float | `Rel of float ] list ] ->
?tangents:[ `NonUniform | `Uniform | `Tangents of V2.t list ] ->
V2.t list ->
t
of_path ?closed ?uniform ?size ?tangents path
Create a bezier function which defines a curve that passes through the points of path
.
size
sets the absolute or relative (as a fraction of segment length) distance that the computed curve can deviate from the input path
. Provided either as a flat value for all points, or a list with a value for each segment of the path
(default = `Flat (`Rel 0.1)
).tangents
provides control over the tangents of the computed curve where it passes through the points of path
. Tangents can either be provided by the user with `Tangents l
, or computed `NonUniform | `Uniform
(see Path2.tangents
). Default is `NonUniform
.closed
is true
(default = false
), an additional segment between the last and first points of path
will be included in the computations. Thus, this impacts the correct lengths of lists provided to the size
and tangents
parameters (= length of path
if closed
, one less if not).closest_point ?n ?max_err t p
Find the fractional position along the bezier t
closest to the point p
. t
is treated as cubic (degree n = 3
) by default, subdividing the bezier by 3
for each degree. Search continues until a position less max_err
(default = 0.01
) distance from p
is found.
deriv ?order ps
Calculate the order
derivative of the bezier defined by the control points ps
. The first derivative is taken by default (order = 1
). Invalid_argument
is raised if order
is below 0
, or the degree of the bezier (length ps - 1
) is lower than the order
.
line_intersection ~line pts
Compute the positions (between 0.
and 1.
) along the bezier curve defined by the control points pts
that line
intersects with.
val quaternion : ?about:V3.t -> Quaternion.t -> t -> float -> V3.t