Struct anima_engine::math::Bezier
[−]
[src]
pub struct Bezier { // some fields omitted }
A struct
useful for creating square and cubic Bézier curves.
Methods
impl Bezier
fn new_sqr(v1: Vector, v2: Vector, v3: Vector) -> Bezier
Creates a square Bézier from v1
to v3
curving towards v2
.
Examples
let b = Bezier::new_sqr( Vector::new(0.0, 0.0, 0.0), Vector::new(1.0, 1.0, 0.0), Vector::new(2.0, 0.0, 0.0) );
fn new_cub(v1: Vector, v2: Vector, v3: Vector, v4: Vector) -> Bezier
Creates a cubic Bézier from v1
to v4
curving towards v2
and v3
.
Examples
let b = Bezier::new_cub( Vector::new(0.0, 0.0, 0.0), Vector::new(0.0, 1.0, 0.0), Vector::new(1.0, 1.0, 0.0), Vector::new(1.0, 0.0, 0.0) );
fn interpolate(&self, ratio: f32) -> Vector
Computes the vector on a Bézier curve correspoding to a ratio
(between 0.0
and 1.0
).
Examples
let b = Bezier::new_sqr( Vector::new(1.0, 0.0, 0.0), Vector::new(1.0, 1.0, 0.0), Vector::new(0.0, 1.0, 0.0) ); assert_eq!(b.interpolate(0.5), Vector::new(0.75, 0.75, 0.0));
let b = Bezier::new_cub( Vector::new(0.0, 0.0, 0.0), Vector::new(0.0, 1.0, 0.0), Vector::new(1.0, 1.0, 0.0), Vector::new(1.0, 0.0, 0.0) ); assert_eq!(b.interpolate(0.5), Vector::new(0.5, 0.75, 0.0));
fn len(&self, steps: i32) -> f32
Computes the approximated length of a Bézier curve by summing the distances between steps
uniformly distrubuted, consecutive points.
Examples
// approximation of radius 1.0 circle arc let b = Bezier::new_cub( Vector::new(0.0, 0.0, 0.0), Vector::new(0.0, 0.55228, 0.0), Vector::new(0.44772, 1.0, 0.0), Vector::new(1.0, 1.0, 0.0) ); const EPSILON: f32 = 0.001; assert!((b.len(20) - consts::PI / 2.0).abs() < EPSILON);