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 ;}