package OCADml

  1. Overview
  2. Docs

Generation and measurement of 3d 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 -> V3.t

A bezier curve function.

val coefs : V3.t list -> V3.t array

coefs ps

Compute the bezier algebraic coefficients for the control points ps.

val make : V3.t list -> t

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..

val curve : ?init:V3.t list -> ?rev:bool -> ?fn:int -> ?endpoint:bool -> t -> V3.t list

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)
  • If rev is true, the bezier will be drawn in reverse (default = false)
  • If 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 -> V3.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.

val patch : V3.t list list -> float -> t

patch grid

Create a bezier patch (curved surface) from an rectangular grid of control points.

val patch_curve : ?fn:int -> (float -> t) -> V3.t list list

patch_curve ?fn p

Sample a grid of fn by fn segments describing a curved surface from the bezier patch p. (default fn = 16).

val of_bezpath : ?n:int -> V3.t list -> t

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 V3.t list ] -> V3.t list -> V3.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).
  • If 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).
val bezpath_curve : ?fn:int -> ?n:int -> V3.t list -> V3.t list

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 V3.t list ] -> V3.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.
  • If 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).
val closest_point : ?n:int -> ?max_err:float -> t -> V3.t -> float

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.

val deriv : ?order:int -> V3.t list -> t

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.

Basic Transfomations

val translate : V3.t -> t -> t
val xtrans : float -> t -> t
val ytrans : float -> t -> t
val ztrans : float -> t -> t
val rotate : ?about:V3.t -> V3.t -> t -> t
val xrot : ?about:V3.t -> float -> t -> t
val yrot : ?about:V3.t -> float -> t -> t
val zrot : ?about:V3.t -> float -> t -> t
val quaternion : ?about:V3.t -> Quaternion.t -> t -> t
val axis_rotate : ?about:V3.t -> V3.t -> float -> t -> t
val affine : Affine3.t -> t -> t
val scale : V3.t -> t -> t
val mirror : V3.t -> t -> t