0
votes

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 though, just somewhere close to it.

Anyone any ideas?

Andrew

3
Bezier splines, by definition, don't pass through their control points (except I guess in degenerate cases). There are cubic splines that do, by design, include the control points (Catmull-Rom), but I know nothing about Flex so I can't say whether those are supported in any way. They're not at all hard to implement; I'm really dumb and I've managed to code it up several times in the past.Pointy
It sounds like you really want to select a location for the drag handle such that the curve passes through your chosen point. Yes? Are your points arbitrary or restricted in some way - i.e. point2 is actually on the bisector of the line from 1 to 3?phkahler

3 Answers

0
votes

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

0
votes

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.

0
votes

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