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.
Are you trying to find curveThru code?http://forums.swishzone.com/index.php?s=d8b09993f33ccb9361b069fda0bbae89&showtopic=923
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.