My first thought was that I wouldn’t have problems by using the curveTo method of the MovieClip class as long this method uses 3 points to create a curve, what was exactly what I needed.
The problem is that this method uses the Bézier formula to create the curve, and the Bézier curve does not pass through the second point, as you can see above:
I strong believe that I wasn’t the first one to have this frustration trying to create a curve on Flash, because that I decided to post the solution.
The formula above is the Bézier formula. Using my second point as B(t), 0.5 as t (the middle of the curve) and isolating the P2 I came to this code:
p3.x = (0.25 * p0.x + 0.25 * p2.x - p1.x) / -0.5;
p3.y = (0.25 * p0.y + 0.25 * p2.y - p1.y) / -0.5;
moveTo(p0.x, p0.y);
curveTo(p3.x, p3.y, p2.x, p2.y);
P0, P1, P2 are the 3 points used to create the curve, P3 is the generated point to replace the P2 on the curveTo method.
Here is the result:
I hope it helps someone! :)
5 comments:
Hi, nice article.
BTW: the beziere formula ist supported natively by the player (from 9 up) in the fl.motion package. Search livedocs for "BezierSegment". Helps to speed up your app and keep code short ;)
Thanks so much, this is just what I needed!
You're welcome :)
Sorry, I had a problem with my old server so I lost that files and I don't have the source anymore. But I'm glad that it helped you.
Awesome! thank you so much!
Post a Comment