Sign in to follow this  

Draw arc from 2 points and radius

This topic is 661 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to draw arc from 2 points and radius, but my drawing algorithm need center + radius + start and end angles for drawing.

 

Center I can easily find, radius already present, but how to find angles?

 

Is there a way to convert start and end points + radius to start and end angles?

 

Does anyone faced with such problem?

Edited by BlackJoker

Share this post


Link to post
Share on other sites

There are two valid solutions for an arc, given two points and a radius. Consider that if the two points form an imaginary line, the arc could be on either side on that line, if unconstrained otherwise.

 

The equation is invalid if the distance between the points is greater than radius * 2, because the arc cannot reach both the points if this is the case. It is also invalid if the points are exactly coincidental, because this would imply that the center would be infinitely far away.

 

For any other case, the center of the arc can be thought to offset from the middle of the two points, perpendicular (or 90 degrees) to the line formed by the points. I don't have the exact formula for the distance, but it can be solved with some arc trigonometry.

 

When you have determined the center offset, you have to pick the side of the line to which to offset the center of the arc. Commonly this is done by defining the order of the two points (start and end) and rotating the formed line 90 degrees about the start point to arrive to a baseline direction. Then you'd take the dot product of said baseline direction and the offset vector to determine which side you're on, and constrain the direction based on that. 

 

 

You can find the angles by observing the tangent of the circle, part of which the arc is. The tangent of a given point on a circle is the vector from the center of the circle to the point, rotated 90 degrees (or pi/2 radians) and starting from said point. The actual angle on the xy plane (about z) is given by atan2(x,y), with x and y being the tangent vector's components.

Edited by Nik02

Share this post


Link to post
Share on other sites

See the attached file.

 

Consider that n1 is the normalized vector from the center to the arc start point p1. Its tangent t1 with respect to the circle is simply n1 rotated 90 degrees. If you need to "place" the tangent vector, move it to start it from the arc point. However, for measuring the screen-space angle of it, you don't have to offset it.

 

angleOfTangent1 = atan2 (t1.x, t1.y)

 

Since you calculate the n1 already, you can find the angle of the tangent vector by swapping the x and y components of the normal n1 (thus implicitly performing the 90deg rotation), and put them to the atan2.

 

You can find the t2 and its angle exactly the same way.

 

Note that common implementations of atan2 return the angle in radians. 90 degrees is pi/2 radians. Also, atan2 is usually a helper layer on top of atan, that considers if either or both components are zero or negative, and adjusts the return value accordingly to arrive to a correct angle across the full circle. Atan, by itself, would only make sense when both parameters are positive.

Edited by Nik02

Share this post


Link to post
Share on other sites

basic trig.

 

theta = atan(y/x)

 

where:

 

theta is the angle from the center to the point (p1 or p2)

 

x,y are the coordinates of the point when the center is at the origin.

 

be sure to adjust accordingly based on which quadrant the point lies in.

 

see trig, unit circle for further info.

 

https://en.wikipedia.org/wiki/Unit_circle

 

https://upload.wikimedia.org/wikipedia/commons/8/8f/Unit_circle.svg

 

note that theta is measured starting from the 3 o'clock position in a counter clockwise direction.  you may need to convert that to the degrees system used by your graphics package.

Share this post


Link to post
Share on other sites

This topic is 661 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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