7 Replies Latest reply on Nov 26, 2007 9:36 PM by kglad

# Drawing a curved line w/ Actionscript

I'm having a tough time trying to dynamically figure out what a control point should be between a start and end point. I would like to consistently get a soft curve between the two points. The ideal curve would look something like this:
http://www.actionscript.org/resources/content_images/4/steps.gif

My problem comes in when I need to figure out the math to get the control point (p1 in that graphic). I see a lot of code out there drawing a sine curve or something more detailed, but I'm getting lost when it's just one curve. Ideally, I think what I'm looking for is a function along these lines:
Code:

function drawCurvedLine(target_mc,startX,startY,endX,endY,curveAngle){
...
}

The "curveAngle" argument would be a degree like 30, 45, etc...

If anybody can help, I would appreciate it greatly. If I'm not thinking about this correctly, let me know.
• ###### 1. Re: Drawing a curved line w/ Actionscript
do you always want a vertical curve? if so, use the average of your startX and endX values for the control points x coordinate. you can experiment with different y-values of the control point to see which you want.
• ###### 2. Re: Drawing a curved line w/ Actionscript
Thanks for the response. It will be variable. I'm drawing from a base point to a destination point (and there are multiple destinations around).
• ###### 3. Re: Drawing a curved line w/ Actionscript
well, you have to have some way to determine your anchor point.

indicating you want the start and end tangents to have the same slope isn't enough to determine your anchor point.
• ###### 4. Re: Drawing a curved line w/ Actionscript
Damn, this makes things tough. I'm still stuck in the visual editing concept of where you can draw a line and grab the middle and adjust the curve that way. It's too bad I couldn't just say that and it could happen, haha..

Thanks for your help. Unless somebody else has any ideas, I'll have to start thinking of another way to do this.
• ###### 5. Re: Drawing a curved line w/ Actionscript
you can do it with actionscript. but you need some way to describe what kind of curve you want. just saying you want the slope to be the same (actually opposites) at the endpoints doesn't completely describe the curve you want. so, noone can tell you where that anchor point should be.
• ###### 6. Re: Drawing a curved line w/ Actionscript
I have a concept, I just don't know where those points are. If the line were always running horizontal, _x would be in the middle of the two points and the _y value would be decreased by some unknown value based on the length of the line.
• ###### 7. Re: Drawing a curved line w/ Actionscript
you may have a concept, but unless you can express that concept in concrete terms, your concept can't be codified.