The principle of the begisel curve and the implementation of the secondary besell Curve

Source: Internet
Author: User
Principle of bezr Curves

The bezr curve is a curve applied to two-dimensional graphics. A curve consists of vertices and control points. By changing the coordinates of a control point, you can change the shape of the curve.

 

One-time bezr curve formula:

A line segment is a continuous point from p0 to P1.

 

Formula of the quadratic bezr curve:

The quadratic bezr curve is a continuous B (t) on a line segment consisting of q0 consecutive points from p0 to P1 and Q1 continuous points from P1 to P2. It describes a parabolic curve.

 

Three-Step besuppliers curve formula:

 

Implementation of quadratic bezr Curves
# Include <vector> class cbeziercurve {public: cbeziercurve ();~ Cbeziercurve (); void setctrlpoint (point & stpt); bool createcurve (); void draw (CDC * PDC); Private: // main algorithm, coordinate void calcurvepoint (float T, point & stpt); Private: // vertex and Control Point array STD: vector <point> m_vecctrlpt; // coordinate array of each point on the curve STD: vector <point> m_veccurvept ;};

 

# Include <math. h> # include "beziercurve. H" cbeziercurve: cbeziercurve () {} cbeziercurve ::~ Cbeziercurve () {} void cbeziercurve: setctrlpoint (point & stpt) {m_vecctrlpt.push_back (stpt);} void cbeziercurve: createcurve () {// ensures a secondary curve, two vertices, one control point assert (m_vecctrlpt.size () = 3); // The increment of T, you can use setp size to determine the number of points on the curve to be saved float step = 0.01; for (float T = 0.0; t <= 1.0; t + = step) {point stpt; calcurvepoint (T, stpt); m_veccurvept.push_back (stpt);} void cbeziercurve :: draw (CDC * PDC) {// draw the point on the curve. If it is not continuous, use a straight line to connect the int ncount = m_veccurvept.size (); For (INT I = 0; I <ncount; ++ I) {PDC-> setpixel (m_veccurvept [I], 0x000000) ;}} void cbeziercurve: calcurvepoint (float T, point & stpt) {// ensure that the curve is a quadratic curve. The two vertices have one control point assert (m_vecctrlpt.size () = 3); // calculate the coordinate of the curve points. This is two algorithms, changing this can achieve multiple curves float x = (float) m_vecctrlpt [0]. x * POW (1-T, 2) + (float) m_vecctrlpt [1]. x * T * (1-t) * 2 + (float) m_vecctrlpt [2]. x * POW (T, 2); float y = (float) m_vecctrlpt [0]. y * POW (1-T, 2) + (float) m_vecctrlpt [1]. y * T * (1-t) * 2 + (float) m_vecctrlpt [2]. y * POW (T, 2); stpt. X = x; stpt. y = y ;}

 

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.