Sign in to follow this  
peterbone

Arc line calculation

Recommended Posts

I'd like to make it possible for a user to drag the end of a line so that it bends in 2D. The line will be an arc when bent (section of a circle). The start point of the line will be fixed in terms of its position and angle/direction. The length of the line/arc will also remain constant. The angle/direction at the end of the line will point to some point P (the cursor position).

That should be enough to define the arc fully. However, it seems non-trivial to work out the parameters of the arc. This is because to work out the position of the end of the arc requires knowledge of the radius or angle at the end of the line and visa-versa. If I could just work out the radius the rest is easy.

 

Here are some relations:

angle at end = angle at start + length/radius

circle centre is perpendicular to start direction at distance radius from start position

circle centre is perpendicular to end direction at distance radius from end position

end direction is vector from end position to point P.

 

I need an equation for radius in terms of the arc start position, direction, arc length and point P. Putting the equations into Maxima to find a closed form solution using 'solve' didn't seem to come up with anything.

Edited by peterbone

Share this post


Link to post
Share on other sites
The equations you get involve trigonometric functions and don't look like a closed-form solution will exist. But you can always solve this numerically: Write the problem as finding a root of a function of one parameter (e.g., the position of the center of the circle in the line where it has to be) and solve using something like Newton's method. Edited by Álvaro

Share this post


Link to post
Share on other sites

Sounds like inverse kinematics :

 

http://freespace.virgin.net/hugo.elias/models/m_ik2.htm

 

 

 

But, if all you need is a line that bends like an arc, I'd recommend a curve/spline/parametric equation of some sort:

 

http://en.wikipedia.org/wiki/Bézier_curve

http://www.blackpawn.com/texts/splines/

http://en.wikipedia.org/wiki/Spline_(mathematics)

Share this post


Link to post
Share on other sites

I know I could use a numerical method, but I'll try everything before I have to resort to that. This needs to be fast.

 

I've thought about using a quadratic bezier curve, but even keeping them a constant length requires a numerical method to work out the length and another numerical method to offset the control point to get it to the length you want. I thought about using arcs because it's easier to keep a constant length. The constant length is the most important aspect. It shouldn't just appear to be the same length - it needs to be exact.

Share this post


Link to post
Share on other sites

I know I could use a numerical method, but I'll try everything before I have to resort to that. This needs to be fast.

Can you clarify this? How many of these per frame do you have to compute? Hundreds of thousands? Numerical methods can be extremely fast. This is particularly true if you can start with a reasonable approximation (e.g., the position from the previous frame).

The constant length is the most important aspect. It shouldn't just appear to be the same length - it needs to be exact.

Your requirements a a bit strange. What are you trying to do exactly?

Share this post


Link to post
Share on other sites

Thanks Alvaro. I will consider numerical solutions but I prefer the simplicity of a formula. My main reason for posting here was to check if I had missed something in the maths that would lead to a simple formula. It seems that that is not the case, so I will look at numerical solutions.

 

This is not actually for a game. I'm developing software for creating animations. Objects are constructed from primitives such as lines, circles and images and then moved using pin joints. Bendy lines will be a new primitive. They need to stay the same length because they will be bendy, not stretchy. If a bendy line is used for an archer's bow for example, you wouldn't expect it to change length.

 

The number of times the calculation needs to be performed depends on the animator. In a complex scene there could be thousands of these arcs needing to be drawn at up to 33fps when the animation is played. I would prefer to do the calculations on the fly.

Edited by peterbone

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this