views:

54

answers:

1

Hi Everybody,
My math knowledge has never been very broad, so this maybe a simple question but I'm not really sure.

Basically I'm using the curveTo function to draw some lines for flight paths, what I'm not sure how to do is dynamically finding the curve points, so for example if you look at the ryan air site: http://www.ryanair.com/en/cheap-flight-destinations all the lines are curved nicely.

current_line.graphics.curveTo(curveX, curveY, map.mouseX, map.mouseY);

I need to find the curveX and curveY

If you need anymore information, leave a comment and I'll answer any questions you have.

Thanks in advance
Will

+1  A: 

If I've understood correctly, I could give you one possible answer, though it's very straightforward. I assume you want to find out how to plot a curve automatically between two points, to avoid just getting a straight line between your two points. So you need to calculate the control point's location.

A simple way would be to just use the y position of the start and end point to find the point that is exactly half way between them on the y-axis, then add some arbitrary value to that, and use it as the control point in the curveTo function. You could calculate the value to add by getting a percentage of the length of the line, so that each curve would look similarly curved.

This would make sense for a flight path type app, as all the curves would curve in an upward direction, mimicking how flight paths are drawn for plane routes. If you don't see what I mean let me know, I'll give you a simple example with real numbers. This may not even be what you're asking anyway!

Edit x4:

Seems coding directly into the answer box wasn't a good idea :P Here's the working, correct way to do it:

CS4 Version: http://dl.dropbox.com/u/3987391/AutoCurve.fla

CS3 Version: http://dl.dropbox.com/u/3987391/AutoCurve-CS3.fla

Let me know if you have problems still!

debu

debu
Hi Debu, This is exactly what I'm looking for. Yeah if it's not too much a problem, could you give me an example of what you mean? I have a basic version working, but it's not perfect. I would like to see how you would do it. Thanks a lot
WillDonohoe
I dunno if it notifies you of edits to answers, so I'm adding a comment to make sure you get notified that I added stuff :)
debu
Hi Debu, Thanks for your reply. That worked a treat, however any points going to the right of the start point went in a direct line?
WillDonohoe
Hi again Will; I missed out a crucial dividing by 2 in one of the calculations, and also I think the problem you're referring to is probably coming about by not using an absolute value, so try with what I've changed it to in my answer above.
debu
Hi Debu, thanks for your time. I've tried adding the division by 2 and changing them to absolute values, but it didn't seem to make any difference to the points to the right of the start point, and made the curves to the left go in a bit of a loop!
WillDonohoe
It's done and working, download that FLA and have a look at the code on the first frame. :)
debu
ok I know that you're going to hate me for this, but do you have a CS3 version you could upload? sorry mate!
WillDonohoe
Haha! Luckily for you CS4 allows you to save in CS3 format - I edited the answer with the new link :)
debu
Debu YOU ARE THE MAN! Thank you so much for the help, that works flawlessly.
WillDonohoe
:D You're very welcome, glad it works as you want.
debu