Search code examples
bezier

How to change a Bezier curve by moving a point on it with the mouse?


Like in Illustrator, for example. I. e., grabbing the curve with the mouse and moving the mouse a certain distance.

This is a similar topic: Drag a bezier curve to edit it

I tried to reproduce tfinniga's answer:

P1 = P1 + k1 * V;
P2 = P2 + k2 * V;

P0 and P3 must remain in place.

Even adding 1 to K, the result does not meet the expectation.

image, point shifted 100 up


Solution

  • You misunderstood the answer from tfinniga's post.

    From tfinniga's post, we have

    P = k0*P0 + k1*P1 + k2*P2 + k3*P3 and 
    P' = k0*P0' + k1*P1' + k2*P2' + k3*P3'
    

    Since you require P0 and P3 unchanged, we have two identities for V

    V = k1*(P1'-P1) + k2*(P2'-P2)
    

    and

    V = P' - P0
    

    So, you can choose

      P1' = P1 + c/k1 * V, 
      P2' = P2 + (1-c)/k2 * V
    

    where c is a constant between 0 and 1.