Drawing part of a Bézier curve by reusing a basic Bézier-curve-function?

后端 未结 2 581
青春惊慌失措
青春惊慌失措 2020-12-01 05:01

Assuming I\'m using some graphic API which allows me to draw bezier curves by specifying the 4 necessary points: start, end, two control points.

Can

2条回答
  •  悲&欢浪女
    2020-12-01 05:28

    In an answer to another question I just included some formulas to compute control points for a section of a cubic curve. With u = 1 − t, a cubic bezier curve is described as

    B(t) = u3 P1 + 3u2t P2 + 3ut2 P3 + t3 P4

    P1 is the start point of the curve, P4 its end point. P2 and P3 are the control points.

    Given two parameters t0 and t1 (and with u0 = (1 − t0), u1 = (1 − t1)), the part of the curve in the interval [t0, t1] is described by the new control points

    • Q1 = u0u0u0 P1 + (t0u0u0 + u0t0u0 + u0u0t0) P2 + (t0t0u0 + u0t0t0 + t0u0t0) P3 + t0t0t0 P4
    • Q2 = u0u0u1 P1 + (t0u0u1 + u0t0u1 + u0u0t1) P2 + (t0t0u1 + u0t0t1 + t0u0t1) P3 + t0t0t1 P4
    • Q3 = u0u1u1 P1 + (t0u1u1 + u0t1u1 + u0u1t1) P2 + (t0t1u1 + u0t1t1 + t0u1t1) P3 + t0t1t1 P4
    • Q4 = u1u1u1 P1 + (t1u1u1 + u1t1u1 + u1u1t1) P2 + (t1t1u1 + u1t1t1 + t1u1t1) P3 + t1t1t1 P4

    Note that in the parenthesized expressions, at least some of the terms are equal and can be combined. I did not do so as the formula as stated here will make the pattern clearer, I believe. You can simply execute those computations independently for the x and y directions to compute your new control points.

    Note that a given percentage of the parameter range for t in general will not correspond to that same percentage of the length. So you'll most likely have to integrate over the curve to turn path lengths back into parameters. Or you use some approximation.

提交回复
热议问题