Results 1 to 6 of 6

Thread: Arc Degrees

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    565

    Arc Degrees

    I tried all kinds of things to calculate the Arc degrees. And did lots of research. Anyways, I made a diagram and I will post my code attempt as well. Any assistance with the getDegreesArcText function would be great

    vb Code:
    1. Private Shared Function getDegreesArcText(g As Graphics, text As String, font As Font, circleRadius As Double) As Double
    2.         Dim degrees As Double
    3.         Dim linearSize As SizeF
    4.         linearSize = g.MeasureString(text, font)
    5.  
    6.         'TODO: use curved line to calculate
    7.         'Dim thePoint As Point = clsJoystickSlim.DegreesToPoint(New Point(0, 0), circleRadius, 10)
    8.         'Dim arcLineSize As Double = joystick.findAngle(New Point(0, 0), New Point(circleRadius, 0), New Point(circleRadius, linearSize.Width)) 'thePoint)
    9.  
    10.  
    11.         degrees = 'linearSize.Width
    12.         Return degrees
    13.     End Function
    14.  
    15.     Public Function findAngle(p1 As Point, p2 As Point, p3 As Point) As Double
    16.         Dim a_x As Double = p2.X - p1.X
    17.         Dim a_y As Double = p2.Y - p1.Y
    18.  
    19.         Dim b_x As Double = 1.0
    20.         Dim b_y As Double = 0.0
    21.  
    22.         Return Math.Acos((a_x * b_x + a_y * b_y) / Math.Sqrt(a_x * a_x + a_y * a_y))
    23.     End Function
    Attached Images Attached Images  
    Last edited by rex64; Nov 8th, 2011 at 03:21 PM. Reason: Image had a mistake on the coordinates.
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  2. #2
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: Arc Degrees

    I'll answer the questions in your diagram. It shouldn't be hard to convert to code.

    We're given a circle centered at (CX, CY) of radius R. There is an arc starting at (CX + R, CY) going counterclockwise a length L. The arc's angle D is related to the other parameters by L = DR, where D is measured in radians. [For instance, if L = 2*pi*R, L is the entire circumference, forcing D = 2*pi.] That is, D = L/R. The coordinates are then just

    (E, F) = (CX + R*cos(D), CY + R*sin(D))
    Last edited by jemidiah; Nov 8th, 2011 at 01:43 PM. Reason: Swapped notation to be consistent with the original post
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    565

    Re: Arc Degrees

    Maybe I missed something, but how do I account for curvedLength (5 in diagram) (the length of the arc in units, not degrees)?

    vb Code:
    1. Public Function findAngle(circleCenter As Point, radius As Double, curvedLength As Double)
    2.         'L = 2*pi*R, L is the entire circumference
    3.         Dim L As Double = 2 * Math.PI * radius
    4.  
    5.         'The arc's angle A is related to the other parameters by L = AR. forcing A = 2*pi. So A = L/R
    6.         Dim A As Double = L / radius
    7.  
    8.         Dim arcDegrees As Double = 0 'WHAT DO I DO HERE?????
    9.  
    10.         Dim e As Double = circleCenter.X + radius * Math.Cos(A)
    11.         Dim f As Double = circleCenter.Y + radius * Math.Sin(A)
    12.  
    13.         'We're given a circle centered at (CX, CY) of radius R. There is an arc starting at (CX + R, CY) going counterclockwise a
    14.         'length L. The arc's angle A is related to the other parameters by L = AR, where A is measured in radians. [For instance,
    15.         'if L = 2*pi*R, L is the entire circumference, forcing A = 2*pi.] That is, A = L/R. The coordinates are then just
    16.  
    17.         '(E, F) = (CX + R*cos(A), CY + R*sin(A))
    18.         Return A
    19.     End Function
    Last edited by rex64; Nov 8th, 2011 at 02:49 PM.
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  4. #4
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Arc Degrees

    Angle(degrees):360 degrees::ArcLenth:Circumference

    A/360 = L/C

    jemidiah gave the formula with radians:

    Angle(radians):2*pi radians::ArcLenth:Circumference

    A/(2*pi) = L/C

    Since the circumference, C, is 2*pi*Radius, this simplifies to

    A = L/R

    If you need the measure in degrees, mutliply by 180/pi

    A = (180*L)/(pi*R)

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    565

    Re: Arc Degrees

    I do not see how you get curvedLength included in this formula. Is L supposed to be curvedLength? And then how does curvedLength fit into this: Dim L As Double = 2 * Math.PI * radius

    vb Code:
    1. Public Function findAngle(circleCenter As Point, radius As Double, curvedLength As Double)
    2.         'L = 2*pi*R, L is the entire circumference
    3.         Dim L As Double = 2 * Math.PI * radius
    4.  
    5.         'The arc's angle A is related to the other parameters by L = AR. forcing A = 2*pi. So A = L/R
    6.         Dim A As Double = L / radius '
    7.  
    8.         Dim arcDegrees As Double = (180 * L) / (Math.PI * radius)
    9.  
    10.         Dim e As Double = circleCenter.X + radius * Math.Cos(A)
    11.         Dim f As Double = circleCenter.Y + radius * Math.Sin(A)
    12.  
    13.         'We're given a circle centered at (CX, CY) of radius R. There is an arc starting at (CX + R, CY) going counterclockwise a
    14.         'length L. The arc's angle A is related to the other parameters by L = AR, where A is measured in radians. [For instance,
    15.         'if L = 2*pi*R, L is the entire circumference, forcing A = 2*pi.] That is, A = L/R. The coordinates are then just
    16.  
    17.         '(E, F) = (CX + R*cos(A), CY + R*sin(A))
    18.         Return A
    19.     End Function
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  6. #6
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Arc Degrees

    Yes, L is the curve length.

    (2 * Math.Pi * radius) is the circumference. jemidiah gave that only as an example. It is not part of the calculation.

    The angle, measured in radians, is CurveLength/Radius. You need radians for the Sin and Cos functions to determine the point (E,F).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width