Calculate degrees om circular arc (math mostly)

artix

Member
Joined
Oct 5, 2007
Messages
16
Location
Sweden
Programming Experience
1-3
I guess this is more a math question then a programming question but im firing it away anyway. :p

What I want to do is getting a formula for finding out the degrees between 2 points in a circular arc..

Like for example, consider the attached image and its two points(p2,p3) and center point(p1) as part of a circular arc stretching 90 degrees. How do I calculate that if all I got is these three points. (which should be more then enough though I guess. hehe )
And will the calculation be different depending on where in the 'circle' the arc starts and end? I guess so?

The reason for this question is that I want to draw an arc using the .NET functions and it seems it only accept start degrees and sweeping degrees to draw the graphics instead of points in a circular arc.. Or am I wrong?
 

Attachments

  • namnlös.JPG
    namnlös.JPG
    2 KB · Views: 54
Not trivial, not trivial at all. To calculate a point in an arc will involve a lot of maths and just after you think that you're getting somewhere you will end up with a quadratic equation to solve. Have a best guess approach...
 
One thing you lack is the side that the arc is. Is the arc the shortest way (compared to the other way around, 270 degrees in your example) or predetermined? With this info you can proceed further.

My approach would be to use the center of the circle as the origin and recalculate all position from there. Then check each quandrant to see where your points are. Each quandrant that is included in your arc add 90 degrees.

Now leaves the problem of those partial quandrants at begining and end of the arc, the heart of the problem. You can use the Math.ATan function to get the angle's value from the position of the point relatively to your new origin. However, you must calculate this differently in each quandrant and for each side of arc (clock wise or counter clock wise relatively to the point we take as beginning would be my way but you choose how to determine that side...).

The key to the solution is the ATan function. Just be careful because it returns a value in radians! If you can't make it, I'll help you out with it. I just can't do that today ;)
 
As it turns out... I do a lot of vector graphic math stuff...

Here's a snippet from my vector function toolset:
VB.NET:
Imports System.math

Module Mod_Vector_Func

    'Returns Dot Product of two vectors defined by 3 points
    Function DotProduct(ByVal P1 As PointF, ByVal P2 As PointF, ByVal P3 As PointF) As Double
        DotProduct = (P1.X - P2.X) * (P3.X - P2.X) + (P1.Y - P2.Y) * (P3.Y - P2.Y)
    End Function

    'Returns Cross Product Length
    Function CrossProductLength(ByVal P1 As PointF, ByVal P2 As PointF, ByVal P3 As PointF) As Double
        CrossProductLength = (P1.X - P2.X) * (P3.Y - P2.Y) - (P1.Y - P2.Y) * (P3.X - P2.X)
    End Function

    'Returns a +/- angle in radians (Theta) between two vectors defined by 3 points 
    Function GetAngle(ByVal P1 As PointF, ByVal P2 As PointF, ByVal P3 As PointF) As Double
        'Since having the +/- is useful for some computations I purposefully do not wrap
        'the GetAngle result with ABS to return an absolute value
        GetAngle = Atan2(CrossProductLength(P1, P2, P3), DotProduct(P1, P2, P3))
    End Function

    'Convert radians to degrees
    Function Deg(ByVal Rad As Double) As Double
        Deg = (Rad * 180) / PI
    End Function

End Module

Does that make sense to you?

With the above functions it might look like:
n = Deg(GetAngle(P1, P2, P3))

My definitions of P1-P3 are slightly different than yours... my P2 is the center point and P1 and P3 are on the circumference.
 
Last edited:
Back
Top