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.