UseCodeDrawing
You will notice that the graphics class has a curveto () that can draw a quadratic béier curve, but there is no plot of the cubic béier curve. Quadratic bégiz curve is built on one control point and two basic points. Cubic bégiz curve requires two control points and two basic points to make the curve smoother. The following figure shows the differences between the two curves:
The mathematical formulas of the two curves are as follows:
With the above formula, the problem is easily solved:
Function cubic_curve (GRA: graphics, pt1, pt2, pt0, pt3)
{
Gra. moveTo (pt0.x, pt0.y );
VaR pos_x;
VaR pos_y;
For (VAR I = 0 ; I <= 1 ; I + = 1 / 100 )
{
Pos_x = Math. Pow (I, 3 ) * (Pt3.x + 3 * (Pt1.x - Pt2.x) - Pt0.x)
+ 3 * Math. Pow (I, 2 ) * (Pt0.x - 2 * Pt1.x + Pt2.x)
+ 3 * I * (Pt1.x - Pt0.x) + Pt0.x;
Pos_y = Math. Pow (I, 3 ) * (Pt3.y + 3 * (Pt1.y - Pt2.y) - Pt0.y)
+ 3 * Math. Pow (I, 2 ) * (Pt0.y - 2 * Pt1.y + Pt2.y)
+ 3 * I * (Pt1.y - Pt0.y) + Pt0.y;
Gra. lineto (pos_x, pos_y );
}
}
Click here to download the source file of an example of besell curve painting
|
Author: Yang Zhou Source: http://yangzhou1030.cnblogs.com The copyright of this article is shared by the author and the blog Park. You are welcome to reprint this article, but you must keep this statement without the author's consent. Please goArticleThe original text link is clearly displayed on the page, and the author reserves the right to pursue legal liability. |