TwelvestoneFlash

AS2 join two point with slight curve


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Stickman
 
2009-11-27

Hello flash peeps,

I'm a dunce when it comes to maths and I have a problem I need help with. I doubt it's especially hard but it's too much for my feeble brain so I'd appreciate any help.

I need to join two points with a line. Easy enough if it's a straight line, but I need the line to have a slight curve. I know how to use curveTo, what I don't know is how to calculate the position of the 'control point' that dictates the shape of the curve.

So here's my (theoretical) code:

start_point = { x:0, y:0 }; end_point = { x:100, y:100 }; control_point = { x:???, y:??? };

line.moveTo(start_point.x, start_point.y); line.curveTo(control_point.x , control_point.y, end_point.x, end_point.y);

I need some mathematical gubbins to calculate where to place control_point.

Thanks in advance for any help.

Stickman
 
2009-11-28

Thanks for the pointers, but in the end I worked it out for myself using the sort of bonehead maths that my brain is capable of understanding (I had a shower, I always seem to think better in the shower).

It goes something like this:

start_point = { x:0, y:0 }; end_point = { x:100, y:100 };

mid_point_x = ( start_point.x + end_point.x ) / 2; mid_point_y = ( start_point.y + end_point.y ) / 2;

line_diff_x = end_point.x - start_point.x; line_diff_y = end_point.y - start_point.y;

control_point = { x:mid_point_x - ( line_diff_y / 10 ), y:mid_point_y + ( line_diff_x / 10 ) };

line.moveTo(start_point.x, start_point.y); line.curveTo(control_point.x , control_point.y, end_point.x, end_point.y);

Basically, work out the midpoint of the line and find a point on a line perpendicular to it. The division by ten is an arbitrary number, this can be changed to give a more or less pronounced curve.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

AS2 join two point with slight curve