Struct bezier_nd::curve::Bezier [−][src]
Implementations
Get the start or end point of the Bezier - index 0 gives the start point, index 1 the end point
Get the distance between the start and end points
Create a new Quadratic Bezier that is a line between two points with one absolute control points
Create a new Cubic Bezier that is a line between two points with two absolute control points
Returns true if the Bezier is a quadratic
Consume the Bezier and return a new Bezier scaled separately in X and Y by two scaling parameters
Apply a function to all of the points in the Bezier
Returns a vector of a combination of the vectors of the bezier
Returns the tangent vector at parameter ‘t’ along the Bezier
This is not necessarily a unit vector
Returns two Bezier’s that split the curve at parameter t=0.5
For quadratics the midpoint is 1/4(p0 + 2*c + p1)
Returns the Bezier between two parameters 0 <= t0 < t1 <= 1
pub fn as_lines(&self, straightness: F) -> BezierLineIter<F, V, D>ⓘNotable traits for BezierLineIter<F, V, D>
impl<F, V, const D: usize> Iterator for BezierLineIter<F, V, D> where
F: Float,
V: Vector<F, D>, type Item = (V, V);
pub fn as_lines(&self, straightness: F) -> BezierLineIter<F, V, D>ⓘNotable traits for BezierLineIter<F, V, D>
impl<F, V, const D: usize> Iterator for BezierLineIter<F, V, D> where
F: Float,
V: Vector<F, D>, type Item = (V, V);
Iterate over line segments that are ‘straight’ enough
pub fn as_points(&self, straightness: F) -> BezierPointIter<F, V, D>ⓘNotable traits for BezierPointIter<F, V, D>
impl<F, V, const D: usize> Iterator for BezierPointIter<F, V, D> where
F: Float,
V: Vector<F, D>, type Item = V;
pub fn as_points(&self, straightness: F) -> BezierPointIter<F, V, D>ⓘNotable traits for BezierPointIter<F, V, D>
impl<F, V, const D: usize> Iterator for BezierPointIter<F, V, D> where
F: Float,
V: Vector<F, D>, type Item = V;
Iterate over points that make ‘straight’ enough lines
Returns true if the Bezier is straighter than a ‘straightness’ measure
A linear bezier is always straight.
A straightness measure for a quadratic bezier (one control point) can be thought of as the ratio between the area of the triangle formed by the two endpoints and the control point (three points must form a triangle on a plane) in relation to the distance between the endpoints (the curve will be entirely within the triangle.
A straightness measure for a cubic bezier (two control points) can be though of similarly, except that the curve now must fit within a volume given by the two control points and the endpoints; hence the straightness is measured in some way by the volume in relation to the distance between the endpoints, but also should be no straighter than the area of any one control point in relation to the disnance between the endpoints (the Bezier may be a planar curve that is quite unstraight but with a volume of zero).
Hence the straightness here is defined as the sum of (the ratio between (the distance of each control point from the straight line between the two endpoints) and (the distance between the two endpoints))
straightness
is thus independent of the length of the Bezier
Calculates the length given a straightness
straightness
is independent of the length of the Bezier
Create a Cubic Bezier that approximates closely a circular arc
The arc has a center C, a radius R, and is of an angle (should be <= PI/2).
The arc sweeps through points a distance R from C, in a circle using a pair of the planar unit vectors in the vector space for the points.
The arc will be between an angle A1 and A2, where A2-A1 == angle, and A1==rotate
Create a Cubic Bezier that is a circular arc focused on the corner point, with v0 and v1 are vectors IN to the point (P)
As it is a circular arc we have a kite P, P+k.v0, C, P+k.v1, where
|P+k.v0 - C| = |P+k.v1 - C| = r; |P-C| = d (i.e. side lengths are r, r, k, k)
with two corners being right-angles. (and d is the length of the kite diagonal opposite these right-angles).
The kite is formed from two d, r, k right-angled triangles; it has two other angles, alpha and 2theta, (alpha = angle between v0 and v1). Hence alpha = 180 - 2theta, theta = 90-(alpha/2)
Hence d^2 = r^2 + k^2; r/d = cos(theta), k/d=sin(theta)
We know cos(alpha) = v0.v1 (assuming unit vectors).
cos(alpha) = cos(180-2theta) = -cos(2theta) = -(2cos^2(theta) - 1) = 1 - 2cos^2(theta)
cos^2(theta) = (1 - cos(alpha)) / 2 = r^2/d^2
sin^2(theta) = (1 + cos(alpha)) / 2
=> d^2 = 2*r^2 / (1 - cos(alpha))
Hence also k^2, and hence d and k.
Then we require an arc given the angle of the arc is 2*theta, which requires a lambda of 4/3 * r * (1/sin(theta)-1) = 4/3 * r * (d/k - 1)
Note though that d^2/k^2 = 1/sin^2(theta) = 2/(1+cos(alpha))
hence d/k = sqrt(2/(1+cos(alpha)))
hence lambda = 4/3 * r * (sqrt(2/(1+cos(alpha))) - 1)
Trait Implementations
Auto Trait Implementations
impl<F, V, const D: usize> RefUnwindSafe for Bezier<F, V, D> where
F: RefUnwindSafe,
V: RefUnwindSafe,
impl<F, V, const D: usize> UnwindSafe for Bezier<F, V, D> where
F: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more