Logicalshift / flo_curves

Bezier curve library for Rust
Apache License 2.0
84 stars 6 forks source link

Examples for creating bezier curves from points and control points? #19

Open markusstephanides opened 2 years ago

markusstephanides commented 2 years ago

Hi!

The library looks really promising but I'm having issues getting started. I'm using the Bevy game engine and I'm trying to create bezier curves so I implemented the Coordinate trait for Bevys Vec3using the newtype pattern. However I'm not able to progress any further from there, even after looking at the source code.

Could you give me some directions or examples given that I have a list of 3D coordinates and with each of these coordinates two 3D Coordinates that represent the handles, how to create a bezier curve from that?

Thank you very much!

Logicalshift commented 2 years ago

This could probably do with being moved to the main documentation, but the README file has instructions for this:

use flo_curves::*;
use flo_curves::bezier;

let curve = bezier::Curve::from_points(Coord2(1.0, 2.0), (Coord2(2.0, 0.0), Coord2(3.0, 5.0)), Coord2(4.0, 2.0));

Documentation here: https://docs.rs/flo_curves/latest/flo_curves/bezier/trait.BezierCurveFactory.html#tymethod.from_points (you can also implement the bezier curve traits yourself to use functionality from flo_curves with other libraries)

This will work with any type that implements the Coordinate trait, not just the built-in Coord2 type. Note there's a lot of extra functionality for things that also implement Coordinate2D