The fastest way to calculate cubic Bezier curves?

Now I am calculating it as follows:

    double dx1 = a.RightHandle.x - a.UserPoint.x;
    double dy1 = a.RightHandle.y - a.UserPoint.y;
    double dx2 = b.LeftHandle.x - a.RightHandle.x;
    double dy2 = b.LeftHandle.y - a.RightHandle.y;
    double dx3 = b.UserPoint.x - b.LeftHandle.x;
    double dy3 = b.UserPoint.y - b.LeftHandle.y;

    float len = sqrt(dx1 * dx1 + dy1 * dy1) + 
        sqrt(dx2 * dx2 + dy2 * dy2) + 
        sqrt(dx3 * dx3 + dy3 * dy3);




    int NUM_STEPS =  int(len * 0.05);

    if(NUM_STEPS > 55)
    {
        NUM_STEPS = 55;
    }
    double subdiv_step  = 1.0 / (NUM_STEPS + 1);
    double subdiv_step2 = subdiv_step*subdiv_step;
    double subdiv_step3 = subdiv_step*subdiv_step*subdiv_step;

    double pre1 = 3.0 * subdiv_step;
    double pre2 = 3.0 * subdiv_step2;
    double pre4 = 6.0 * subdiv_step2;
    double pre5 = 6.0 * subdiv_step3;



    double tmp1x = a.UserPoint.x - a.RightHandle.x * 2.0 + b.LeftHandle.x;
    double tmp1y = a.UserPoint.y - a.RightHandle.y  * 2.0 + b.LeftHandle.y;

    double tmp2x = (a.RightHandle.x - b.LeftHandle.x)*3.0 - a.UserPoint.x + b.UserPoint.x;
    double tmp2y = (a.RightHandle.y - b.LeftHandle.y)*3.0 - a.UserPoint.y + b.UserPoint.y;

    double fx = a.UserPoint.x;
    double fy = a.UserPoint.y;

    //a user
    //a right
    //b left
    //b user

    double dfx = (a.RightHandle.x - a.UserPoint.x)*pre1 + tmp1x*pre2 + tmp2x*subdiv_step3;
    double dfy = (a.RightHandle.y - a.UserPoint.y)*pre1 + tmp1y*pre2 + tmp2y*subdiv_step3;

    double ddfx = tmp1x*pre4 + tmp2x*pre5;
    double ddfy = tmp1y*pre4 + tmp2y*pre5;

    double dddfx = tmp2x*pre5;
    double dddfy = tmp2y*pre5;

    int step = NUM_STEPS;



    while(step--)
    {


        fx   += dfx;
        fy   += dfy;
        dfx  += ddfx;
        dfy  += ddfy;
        ddfx += dddfx;
        ddfy += dddfy;
        temp[0] = fx;
        temp[1] = fy;
        Contour[currentcontour].DrawingPoints.push_back(temp);
    }


    temp[0] = (GLdouble)b.UserPoint.x;
    temp[1] = (GLdouble)b.UserPoint.y;
    Contour[currentcontour].DrawingPoints.push_back(temp);

I am wondering if there is a faster way to interpolate cubic beziers?

thank

+3
source share
4 answers

Another point, which is also very important, is that you approximate your curve using a lot of segments of straight length with a fixed length. This is ineffective in areas where your curve is almost straight, and can lead to an unpleasant angular poly-line, where the curve is very curved. There is no easy compromise that will work for high and low curvatures.

, (, , , . , , , ). , , - () .

, "", , , , .

"", , "".

+2
+3

, , ( ) , " ": - , - , " " " " ) - , , , )

, .

, , , , .

: , , , ( ); .

, , node. , 0/+ 1 x y, .

-, -. 8- , 8 , 256: "" .

16 ( ): , , , +/- 2 ( 32- integer): 16 , 28 , "" , 56 - 64- .

32-, 2 ^ 15 ( 15 ) ( , Bresenham, - ), 16 (4 ) , 11 , 2048x2048.

2048x2048 , , 16 - ( - orignal - , 0% , , 100% , )

-, -, - . , .

, , , , . (, 16 , , 16 ).

0

, " ". "" ( 0 180 °) , , .

, , , .

, " " " ". ... , " " : , .

, , " ", : , "" ( ). , , , 1/4, ; ( , ):

  • , - ,

  • , , ,

, , ):

  • " " , , . ( , , 3 )

  • " " 1/4, , " ".

  • " " , , ( 2 , , , , 2 , , ).

  • , " " , "" ( ), " " ( , " ".

  • , " ", , . .

, , ; 32 , , 2 ^ 32 ( , " " , 1/2 , "" , " ", 1/2 ^ 32 ).

0

Source: https://habr.com/ru/post/1753468/


All Articles