Besserl Curve Generation Algorithm

Source: Internet
Author: User

Here we will first introduce another typical curve approximation method, called the bezr curve. I must have learned all about graphics and images, so I will not talk about concepts.
This curve is divided into one/two/three/multiple besell curves to better understand its meaning.

The one-time besell curve is actually a straight line connecting two points.
A quadratic bésel curve is a parabolic curve between two points. A control point is used to control the shape of a parabolic curve.
Three times of the besell curve, a starting point, an ending point, and two control points are required to control the shape of the curve.
Example:

The general algorithm for generating the besell curve can be expressed as follows:

Typedef struct
{
Float X;
Float y;
} Point2d;
/* CP is an array of four elements:
CP [0] is the starting point, or P0 in
CP [1] is the first control point, or p1
CP [2] is the second control point, or p2
CP [3] is the end point, or P3 in
T is the parameter value, 0 <= T <= 1 */
Point2d pointoncubicbezr (point2d * CP, float T)
{
Float ax, BX, CX; float ay, by, Cy;
Float tsquared, tcubed; point2d result;
/* Calculate the polynomial coefficient */
Cx = 3.0 * (CP [1]. X-CP [0]. X );
BX = 3.0 * (CP [2]. X-CP [1]. X)-cx;
Ax = CP [3]. X-CP [0]. X-cx-bx;
Cy = 3.0 * (CP [1]. Y-CP [0]. y );
By = 3.0 * (CP [2]. Y-CP [1]. Y)-cy;
Ay = CP [3]. Y-CP [0]. Y-cy-;
/* Calculate the point value at the T position */
Tsquared = T * t;
Tcubed = tsquared * t;
Result. x = (ax * tcubed) + (BX * tsquared) + (CX * t) + CP [0]. X;
Result. Y = (Ay * tcubed) + (by * tsquared) + (CY * t) + CP [0]. Y;
Return result;
}
/* Computebesuppliers fill in the point2d structure array with the curve points generated by the control point CP.
The caller must allocate sufficient space for output. <sizeof (point2d) numberofpoints> */
Void computebezr (point2d * CP, int numberofpoints, point2d * curve)
{
Float DT; int I;
Dt = 1.0/(numberofpoints-1 );
For (I = 0; I <numberofpoints; I ++)
Curve [I] = pointoncubicbezr (CP, I * DT );
}

This algorithm can be used to conveniently implement point interpolation ~ Therefore, there is a smooth curve.
Of course, based on this, there are many improved methods to quickly generate curves.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.