Curve a line to reach desired distance fom its base?

Started by
1 comment, last by moosedude 15 years, 9 months ago
Okay, I don't know how to explain this but ill try... I need this to work for a project that im programming in flash I have a line with a specified length, going from a specified base-point this line rotates so that it always points at the mouse-cursor. but if the distance between its base-point and the mouse-cursor is less than the line-length, I want to curve the line, with a specified amount of segments, so that its end-point is equal to the mouse-point. I don't know how to do the curve effect properly though. I tried letting the total curvature of the line be PI*2 radians(360 degrees) if the distance is 0, and 0 if the distance is greater than the length, and have a constant change between that that of course, wouldnt produce the correct result, the line-end-point and the mouse-point are only equal when the distance is zero or equal to the lineLength. The distance from the end point to the initial point shouldn't change at a constant rate. It's a trigonometric issue someone told me. this flash demonstrates it, and you might get a better idea of what I'm after. http://img80.imageshack.us/my.php?image=curvelineie1.swf I heard the entire arc in radians should be the arc cosine of(distance / lineLength) * 2 this produced a better result but thats still not it. you can see that here: http://img157.imageshack.us/my.php?image=cloxcurvetoty2.swf I really hope someone here can help me with this. I would *really* appreciate it. Any comments or small help is welcome, and if there's anything else i need to specify to make it easier for you to help me then just tell me.. Thanks in advance!
____________________________________________You don't need a reason to help people. -Zidane/FF9
Advertisement
In short, there's no explicit expression.
I think theres alot of special conditions that you have to take into consideration. At some point if the destination point of the curve gets too close to the origin the equation is going to fail and also which direction the line will curve in is important, if the destination point is above the origin point it should curve up, otherwise curve down. (perhaps?)

my initial thought (and this maybe because I'm working with this stuff at the moment) is too divide the line into many equal length lines and use an inverse kinematics solution to "strech" the end point to the destination. You would then render these lines using a spline joining all their end points together. The result would depend alot on the type of spline you used (i.e catmull-rom, b-spline).

Not sure how well that would work until it was coded up and played with for a bit.

/edit

just watched the flash animation, that does look like a IK solution with some restraints added.

http://en.wikipedia.org/wiki/Inverse_kinematics

please don't get bogged down in the maths for this, its actually very simple; a basic algorithm essentially loops through the line segments starting from the origin and points the line at the destination, this is repeated until the last line in the chain reaches the destination or if all lines are straight.
http://www.fotofill.co.uk

This topic is closed to new replies.

Advertisement