开发者

Finding the apex of a bezier curve

I'm working in flex, although I reckon this is a language independent problem. I'm trying to draw a curve using 3 points, using curveTo (a quadratic bezier function, I don't believe Flex has any other, if it does, please correct me!) Points 1 and 3 are "nodes", with point 2 being a drag handle.

What I want is not for the line to curve towards point 2 but in fact pass through it. I've managed to get this working by fluking it - by doubling the (distance between the midpoint of a line between Points 1 and 3) and Point 2.

This doesn't put it on the Apex of the line开发者_C百科 though, just somewhere close to it.

Anyone any ideas?

Andrew


the quadric bezier curve is calculate using the formula

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

where P0,P1 and P2 are the 3 points you specify. The curve starts in P0 and ends in P2 t ranges from 0 to 1 the apex should be reached at t = 0.5 so try to insert P0, P2 and t = 0.5 into the formula set it equal to the point where you want the apex to be and extract P1 from the formula


Us this formula: B'(t) = 3 (1 - t) 2 (P1 - P0) + 6 (1 - t) t (P2 - P1) + 3 t2 (P3 - P2)

You can use the derivative to find maximums and minimums.


A Bezier spline will not pass through its control points, but a Catmull Rom spline will.

B(t) = ((2*P1)+(-P0+P2)*t + (2*P0-5*P1+4*P2-P3)*t*t + (-P0+3*P1-3*P2+P3)*t*t*t )) / 2

Although this is a cubic rather than quadratic spline. You could try making P1=P2

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜