Curves (curves v0.1.0)

Copy Markdown View Source

Usage

The basic cycle goes like this:

  1. start with a list of {x, y} tuples. These can be any combination of integers and floats.
  2. build a Curves.Curve struct by passing the list of tuples into Curves.define_curve/2
  3. To find a point in the curve struct, call Curves.solve/3 with a float (0.0 - 1.0)

For example:

curve = Curves.define_curve([
# {x,   y}
  {0,   0},
  {0,   0.5},
  {0.8, 0.4},
  {1,   1}
])

t = 0.25 # i.e. 25% from beginning to end of the curve.

{x, y} = Curves.solve!(curve, t)

{0.1280975341796875, 0.28279876708984375} = {x, y}

Summary

Functions

Build a new Bezier Curve struct.

Given a struct, and t, find the point along the curve

See Curves.Bezier.Curve.solve!/3.

Functions

define_curve(points, opts \\ [])

Build a new Bezier Curve struct.

Examples

iex> c = Curves.define_curve([{0.1, 0.9}, {0.5, 0.9}, {0.5, 0.1}, {0.75, 0.1}])
iex> is_struct(c, Curves.Curve)
true

solve(curve, t, opts \\ [])

Given a struct, and t, find the point along the curve

Examples

iex> c = Curves.define_curve([{0.1, 0.9}, {0.5, 0.9}, {0.5, 0.1}, {0.75, 0.1}])
iex> Curves.solve(c, 0.3)
{0.3695499897003174, 0.727199912071228}

Options

  • :float_dtype (default: nil) | If set to an integer, passes results to Float.round(_, precision)

solve!(curve, t, opts \\ [])

See Curves.Bezier.Curve.solve!/3.