Jump to content

  • Log In with Google      Sign In   
  • Create Account


Curve a line to reach desired distance fom its base?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Oggan   Members   -  Reputation: 146

Like
0Likes
Like

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. 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: 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!

Sponsor:

#2 hanstt   Members   -  Reputation: 259

Like
0Likes
Like

Posted 01 July 2008 - 10:15 PM

In short, there's no explicit expression.

#3 moosedude   Members   -  Reputation: 145

Like
0Likes
Like

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS