


# cubicbezier








A library for constructing and evaluating cubic Bézier curve paths.








## Install








```lisp




(ql:quickload :cubicbezier)




```








## Usage








```lisp




(makecurve points &key (divisions 100))




```




Create a cubic Bézier curve path from the given sequence of `points`. `points` is a sequence of




3dimensional vectors as constructed with `#'origin.vec3:vec`. `divisions` is the number of




subdivisions to use when estimating the arclength of the curve path: see the documentation for




`#'evaluate` for more information.








```lisp




(addpoints curve points)




```




Append the specified `points` to `curve`. `points` should be a sequence of 3dimensional vectors




as constructed with `#'origin.vec3:vec`. NOTE: It is an error to add less than a segment worth of




points. A cubic Bézier curve is defined by 4 points for the first segment, and three points for each




successive segment (since the first point of a segment is shared with the last point of the previous




segment.)








```lisp




(editpoint curve index value)




```




Edit the point of `curve` at index `index` with `value`. `value` should be a 3dimensional vector




as constructed with `#'origin.vec3:vec`.








```lisp




(evaluate curve parameter &key evenspacingp)




```




Evaluate `curve` at parameter `parameter`. If `evenspacingp` is nonNIL, arclength




reparameterization is applied, which evenly spaces points along the curve. The number of points is




defined by the `divisions` argument supplied when constructing the curve with `#'makecurve`.




Arclength reparameterization is a remapping of `parameter` before evaluating the curve, in order to




allow for uses such as animation along a curve with a constant velocity.








```lisp




(pointcountvalidp pointcount)




```




Check whether the integer `pointcount` is a valid number of points for a cubic Bézier curve




path. To be valid, there must be at least 4 points, any increment of 3 thereafter: (4, 7, 10, 13,




...).








```lisp




(pointindexpresentp curve index)




```




Check if `curve` has a point at index `index`.








```lisp




(collectpoints curve count &key evenspacingp)




```




Evaluate `count` points along curve, returning a list of 3dimensional vectors. If




`evenspacingp` is supplied, arclength reparameterization is applied: see the documentation for




`#'evaluate` for more information.








```lisp




(collectsegments curve count &key evenspacingp)




```




Collect a list of `count` segments of `curve`. A segment is a list of two 3dimensional vectors.




If `evenspacingp` is supplied, arclength reparameterization is applied: see the documentation




for `#'evaluate` for more information.








## License








Copyright © 20212022 Michael Fiano <mail@mfiano.net>.








Licensed under the MIT License.
