Draw the besell curve using ActionScript in Flash

Source: Internet
Author: User
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.

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.