Struct bezier_nd::curve::Bezier[][src]

pub struct Bezier<F, V, const D: usize> where
    F: Float,
    V: Vector<F, D>, 
{ /* fields omitted */ }

Implementations

Get the start or end point of the Bezier - index 0 gives the start point, index 1 the end point

Deconstruct and get the endpoints

Get the distance between the start and end points

Create a new Bezier that is a line between two 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 straight line

Returns true if the Bezier is a quadratic

Returns true if the Bezier is a cubic

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 point at parameter ‘t’ along 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

Iterate over line segments that are ‘straight’ enough

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Display the `Bezier’ as sets of points

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.