Find the tangent of a point on a cubic bezier curve

前端 未结 5 818
庸人自扰
庸人自扰 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

    I found it too error-prone to use the supplied equations. Too easy to miss a subtle t or misplaced bracket.

    By contrast, Wikipedia provides a much clearer, cleaner, derivative IMHO:

    ...which implements easily in code as:

    3f * oneMinusT * oneMinusT * (p1 - p0)
    + 6f * t * oneMinusT * (p2 - p1)
    + 3f * t * t * (p3 - p2)
    

    (assuming you have vector-minus configured in your language of choice; question isn't marked as ObjC specifically, and iOS now has several langs available)

提交回复
热议问题