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:
Private Shared Function getDegreesArcText(g As Graphics, text As String, font As Font, circleRadius As Double) As Double
Dim degrees As Double
Dim linearSize As SizeF
linearSize = g.MeasureString(text, font)
'TODO: use curved line to calculate
'Dim thePoint As Point = clsJoystickSlim.DegreesToPoint(New Point(0, 0), circleRadius, 10)
'Dim arcLineSize As Double = joystick.findAngle(New Point(0, 0), New Point(circleRadius, 0), New Point(circleRadius, linearSize.Width)) 'thePoint)
degrees = 'linearSize.Width
Return degrees
End Function
Public Function findAngle(p1 As Point, p2 As Point, p3 As Point) As Double
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
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:
Public Function findAngle(circleCenter As Point, radius As Double, curvedLength As Double)
'L = 2*pi*R, L is the entire circumference
Dim L As Double = 2 * Math.PI * radius
'The arc's angle A is related to the other parameters by L = AR. forcing A = 2*pi. So A = L/R
Dim A As Double = L / radius '
Dim arcDegrees As Double = (180 * L) / (Math.PI * radius)
Dim e As Double = circleCenter.X + radius * Math.Cos(A)
Dim f As Double = circleCenter.Y + radius * Math.Sin(A)
'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 A is related to the other parameters by L = AR, where A is measured in radians. [For instance,
'if L = 2*pi*R, L is the entire circumference, forcing A = 2*pi.] That is, A = L/R. The coordinates are then just
'(E, F) = (CX + R*cos(A), CY + R*sin(A))
Return A
End Function
I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.