Find the tangent of a point on a cubic bezier curve

前端 未结 5 824
庸人自扰
庸人自扰 2020-11-29 23:43

For a cubic Bézier curve, with the usual four points a, b, c and d,

for a given value t,

how to most elegantly find the tangent at

5条回答
  •  半阙折子戏
    2020-11-30 00:09

    The tangent of a curve is simply its derivative. The parametric equation that Michal uses:

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

    should have a derivative of

    dP(t) / dt =  -3(1-t)^2 * P0 + 3(1-t)^2 * P1 - 6t(1-t) * P1 - 3t^2 * P2 + 6t(1-t) * P2 + 3t^2 * P3 
    

    Which, by the way, appears to be wrong in your earlier question. I believe you're using the slope for a quadratic Bezier curve there, not cubic.

    From there, it should be trivial to implement a C function that performs this calculation, like Michal has already provided for the curve itself.

提交回复
热议问题