How do I implement a Bézier curve in C++?

前端 未结 5 1338
有刺的猬
有刺的猬 2020-11-30 18:53

I\'d like to implement a Bézier curve. I\'ve done this in C# before, but I\'m totally unfamiliar with the C++ libraries. How should I go about creating a quadratic curve?

5条回答
  •  悲哀的现实
    2020-11-30 19:15

    You have a choice between de Casteljau's method, which is to recursively split the control path until you arrive at the point using a linear interpolation, as explained above, or Bezier's method which is to blend the control points.

    Bezier's method is

     p = (1-t)^3 *P0 + 3*t*(1-t)^2*P1 + 3*t^2*(1-t)*P2 + t^3*P3 
    

    for cubics and

     p = (1-t)^2 *P0 + 2*(1-t)*t*P1 + t*t*P2
    

    for quadratics.

    t is usually on 0-1 but that's not an essential - in fact the curves extend to infinity. P0, P1, etc are the control points. The curve goes through the two end points but not usually through the other points.

提交回复
热议问题