Actually, you're right. if your endpoints will never
move, you can still use a quadratic bezier.
The percentage would be
(mc._x - firstpoint.x)/(lastpoint.x - firstpoint.x)
Since you're using curveTo, you already have all the
points you need for the formula Here's a function for
you:
import flash.geom.Point;
function getPoint(first:Point, last:Point,
control:Point, ratio:Number):Point {
var pReturn:Point = new Point();
var b:Number = 1-ratio;
pReturn.x = (b*b*first.x) + (2*ratio*b*control.x) +
(ratio*ratio*last.x);
pReturn.y = (b*b*first.y) + (2*ratio*b*control.y) +
(ratio*ratio*last.y);
return pReturn;
}
first if the first point in your curve, last is the
last, control is the point specified by the first two
arguments in the curveTo method.
This will give you the closest point on the line to
your MC's position. If you only want to snap if the MC
is within a certain distance, just check the
difference of the ys of your mc's position, and the
returned point.
--- leolea <[EMAIL PROTECTED]> wrote:
> On 4/25/07 5:31 PM, "Joshua Sera"
> <[EMAIL PROTECTED]> wrote:
>
> > If you know that the two endpoints of the curve
> are
> > always going to have an equal x or y value, the
> you
> > can just use the quadratic formula, and get the
> right
> > Y value.
>
> The two endpoints will never move. The middlepoint
> will be the only one
> moving.
>
> So now I just need the quadratic formula ... I
> googled "quadratic formula"
> and I couldn't figure it out nor translate it to my
> Flash needs.
>
> Like I said, I'm (almost) totally math impaired !
>
> > If the endpoints are arbitrary, it's a bit more
> > complicated. Bezier curves take a number from 0 to
> 1
> > and give you a point along the curve. Plugging 0
> into
> > the formula gives you the first endpoint, 1 gets
> you
> > the last, and anything else gives you something in
> > between.
> >
> > This means you're going to have to figure out
> where
> > along the curve your MC is closest to, which
> involves
> > some vector math.
> >
>
> Since I know the _x position of MC, in order to
> figure out where the MC is
> along the curve... Can't I use its _x "percentage":
>
> MC._x / (lastpoint.x - firstpoint.x)
>
> Just curious, but I don't think I need this since my
> two endpoints will not
> move.
>
> > If you want, I can draw out the way I'd approach
> it.
>
> Of course I'd be more than happy to see that.
>
>
>
>
> _______________________________________________
> [email protected]
> To change your subscription options or search the
> archive:
>
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com