Divide bezier curve into two equal halves

前端 未结 3 1164
走了就别回头了
走了就别回头了 2020-12-14 05:04

I have the bezier curves between 2 points. I\'d like to cut all curves into two equal half. One of my idea is if I can control \'t\' value I\'ll draw 2 curves by t = [0,0.5]

3条回答
  •  一个人的身影
    2020-12-14 05:32

    Splitting a bezier into two curves is fairly simple. Look up De Casteljau's Algorithm. https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm

    Update

    De Casteljau is simpler than it looks. That WP article could be clearer for non-mathermeticians. So I'll explain more simply.

    Imagine you have a bezier defined by the points A,B,C & D. Where A and D are the endpoints and B and C are the control points.

    So, say you wanted to find the value of the curve at point 't' along the curve (where t is in the range 0..1. You can do it this way by geometry:

    1. Find the point E that is at 't' along the straight line AB.
    2. Find the point F that is at 't' along the straight line BC.
    3. Find the point G that is at 't' along the straight line CD.

    4. Find the point H that is at 't' along the straight line EF.

    5. Find the point J that is at 't' along the straight line FG.

    6. Finally, find the point K that is at 't' along the straight line HJ.

    K is also equal to the point that is 't' along the bezier. This is De Casteljau's Algorithm.

    But usefully, it also gives us the control points of the two beziers that would result if the curve was split at point K. The two bezier curves are: A,E,H,K and K,J,G,D.

    In your case t=0.5, so finding the two curves is just a sequence of additions and divides-by-2.

      E = (A+B)/2
      F = (B+C)/2
      G = (C+D)/2
      H = (E+F)/2
      J = (F+G)/2
      K = (H+J)/2
    

    Obviously each of these calculations has to be done for x and y.

    Hope this helps.

提交回复
热议问题