2 Replies Latest reply on May 16, 2006 7:35 PM by Lukewig

    Getting coordinates from besier curves

    RenoRich
      Hi....I wrote this algorithm for a besier curve...

      I want to have objects passing through my curve. So what I'm realy looking for is somekinda equation with my besier curve where I would pass in the distance my object has reached and I would get in return the corresponding coordinate on the besier curve. Can anyone help?
        • 1. Re: Getting coordinates from besier curves
          James Newton, ACP Level 3
          You may find some inspiration in the Random Rotation and Movement behavior in the Library Palette, under Animation > Automatic.
          • 2. Re: Getting coordinates from besier curves
            Lukewig Level 1
            Hi,

            I use a script like this to generate a list of points along a bezier curve. Perhaps your algorithm could be implemented in a similar way. To animate an object along the curve, the object steps through the list of points.
            -- script("AnimPathMaker")
            ...
            on GetBezierPath (me, fromPnt, toPnt, numSteps)
            -- returns a list on points along a bezier curve. Handy for animating
            -- a sprite from its current loc to another.

            animList = []

            -- strength of 'arc' (fiddle with these values for your taste)
            yhandleDistance = (toPnt.locH - fromPnt.locH) * 0.4
            xhandleDistance = (toPnt.locV - fromPnt.locV) * 0.4
            --
            x1 = fromPnt.locH
            y1 = fromPnt.locV
            x2 = x1 + xhandleDistance
            y2 = y1 - yhandleDistance
            x4 = toPnt.locH
            y4 = toPnt.locV
            x3 = x4 - xhandleDistance
            y3 = y4 + yhandleDistance

            curveList = []

            cx = 3 * (x2 - x1)
            cy = 3 * (y2 - y1)
            bx = 3 * (x3 - x2) - cx
            by = 3 * (y3 - y2) - cy
            ax = x4 - x1 - cx - bx
            ay = y4 - y1 - cy - by
            --
            numStepsFloat = float(numSteps)
            repeat with i = 1 to numSteps
            t1 = float (i) / numStepsFloat
            t2 = (t1 * t1)
            t3 = (t2 * t1)
            x = integer (ax * t3 + bx * t2 + cx * t1 + x1)
            y = integer (ay * t3 + by * t2 + cy * t1 + y1)
            curveList.append(point(x,y))

            end repeat

            return curveList
            end


            The script to animate a sprite along the curve would look like this:

            on mouseDown (me)
            fromPnt = sprite(1).loc
            toPnt = the mouseLoc
            steps = 40
            AnimList = script("AnimPathMaker").GetBezierPath(fromPnt, toPnt, steps)
            end

            on enterframe (me)
            if count(AnimList) then
            nextSpot = AnimList[1]
            AnimList.deleteAt(1)
            sprite(1).loc = nextSpot
            end if
            end

            -- Luke