**0**

# Curve a line to reach desired distance fom its base?

Started by Oggan, Jul 01 2008 09:27 PM

2 replies to this topic

###
#1
Members - Reputation: **146**

Posted 01 July 2008 - 09:27 PM

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.

Sponsor:

###
#3
Members - Reputation: **145**

Posted 01 July 2008 - 10:30 PM

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.

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.