0
votes

I need to display a bezier curve. The user chooses arbitrary points by clicking on the display area.

I implemented code to make a bezier curve with these points, but for higher order curves it doesn't work, once the order is equal the number of control points-1.

How can I split these control points to make a sequence of cubic bezier curves that represents the entire curve I want?

1
possible duplicate of Convert a quadratic bezier to a cubic?Augwa
You seem to have two things going on. You say “I implemented a code to make a bezier curve with these points, but for higher orders it doesn`t work”. If you show us your code and tell us what's wrong with the output, maybe we can help you fix it. That may be a completely different problem than approximating a higher-order Bézier curve using cubic Bézier segments. Which problem do you really want to solve? (Note that you cannot, in general, find a set of cubic segments that contain exactly the same points as the original higher-order curve.)rob mayoff
@robmayoff The code I made uses all the points, so the order will be too high and will not work. Therefore I want to split in cubic curves. No need to be exactly the same curve, but a good enought approximation.G_comp
Can you explain why you think you even need to split the control points? Do you not want to approximate a high order curve with cubic curves or something? If your users place n points, you can quite easily draw the corresponding nth order curve (using n+(n-1)+(n-2)+...+1 = n(n+1)/2 linear interpolations for each point on the curve you want drawn)Mike 'Pomax' Kamermans

1 Answers

3
votes

I'm sure you can find good resources on "drawing smooth Bezier curves" using adaptive methods, but here is what I think is a good simple approach (if rather unoptimized):

  • Generate binomial coefficients. For example, a 5th degree curve can be expressed as:

    Expanded Bezier polynomial

    The binomial coefficients are the nth row of Pascal's Triangle:

    1, 5, 10, 10, 5, 1
    
  • Adaptively perform recursions at locations where successive divisions produce a significant change in the evaluated points. This happens at cusps/sharp bends where it takes many points to converge to an acceptable solution. For example:

    Note that ||B(a) - B(b)|| is notation for the length
    of the line between the evaluated points B(a) and B(b).
    
    Evaluate B(t) for values of t = a, b,    c,   d,    e
                                  = 0, 0.25, 0.5, 0.75, 1.
    
    Evaluate lengths of straight line segments:
        ac = ||B(a) - B(c)||
        ce = ||B(c) - B(e)||
    
        Also evaluate ab, bc, cd, de.
    
    if  ac - (ab + bc)  >  ERROR_THRESHOLD
        Split ab into two segments and split bc into two segments.
    else
        We have found a good enough approximation.
    
    Do the same as above for ce - (cd + de).