The control points of Bezier curve are obtained through data calculation, and then the points are drawn into curves through the drawing function of flutter.
The difference between using package and drawing your own path
The common method of tracing points according to the position of elements will leave a gap. Only after the control points are calculated can the element information be completely filled. For example, in the following picture, the coordinates of the points used are the same, but the styles cut out are different. The function I want to provide is to restore the design style as much as possible. And after using the package, you only need to confirm the coordinates of each point, without other complex calculations, and the code is more concise.
BezierCurveDots Coordinates of Bezier curve control points
parameter
type
default
describe
x1
double
The X-coordinate of the first point
y1
double
The Y-coordinate of the first point
x2
double
The X-coordinate of the second point
y2
double
The Y-coordinate of the second point
Static function of ProsteBezierCurve
BezierCurveDots calcCurveDots(BezierCurveSection param) Obtain the coordinates of the control points after calculation, and draw the path after obtaining the control points, such as drawing curves with multiple edges or combining the curves with other drawing rules
ThirdOrderBezierCurveSection Fragment for drawing third order Bezier curve
parameter
type
default
describe
p1
Offset
The coordinates of the first point
p2
Offset
The coordinates of the second point
p3
Offset
The coordinates of the third point
p4
Offset
The coordinates of the fourth point
smooth
double
.5
The greater the value of smoothness 0 ~ 1, the straighter the value is, the smaller the value is, and the larger the arc is. When the drawing distance is short and saw tooth appears, try to increase this value
The position coordinates of the four points can refer to the figure below. The starting and ending points are P1 and P4 respectively.Picture sample URL。You can understand that four points form a rectangle, and the four coordinates are the positions of the four points. The curve will be drawn in the rectangle.
We can also draw a single arc graph through the third-order Bessel function, need P1 and P4 are on the same side,But that brings up the problem that was stated at the beginning,The arc does not cling to the bottom.
ThirdOrderBezierCurveDots Coordinates of third order Bezier curve control points
parameter
type
default
describe
x1
double
The X-coordinate of the first point
y1
double
The Y-coordinate of the first point
x2
double
The X-coordinate of the second point
y2
double
The Y-coordinate of the second point
x3
double
The X-coordinate of the third point
y3
double
The Y-coordinate of the third point
Static function of ProsteThirdOrderBezierCurve
ThirdOrderBezierCurveDots calcCurveDots(ThirdOrderBezierCurveSection param) Obtain the coordinates of the control points after calculation, and draw the path after obtaining the control points, such as drawing curves with multiple edges or combining the curves with other drawing rules