I am having difficulty knowing what side of a circle I am getting segments for. Most of the time I need the red section of the circle. This red section can be anywhere around the circle. I can tell what side I need by comparing the distance for the center to the mid point to the arc height. The code have have works most of the time but fails when the red section is at different locations around the circle. I hope I have explained well enough for someone to give me some help.
Dim ArcHeight As Double = xyz.GetArcHeight
Direction = GetDirection222(lstxyz)
If xyz.GetArcHeight < xyz.Radius Then
If startAngle > endAngle Then
endAngle += 2 * Math.PI
End If
Else
Console.WriteLine("What To do?")
If startAngle > endAngle Then
endAngle += 2 * Math.PI
End If
End If
Dim sweepAngle As Double = endAngle - startAngle
' Calculate the arc length
Dim arcLength As Double = radius * sweepAngle
' Define the desired length of each segment as a fraction of the arc length
Dim segmentLengthFraction As Double = 0.01 ' Adjust this value to control the segment length as a fraction of the arc length
' Calculate the number of segments based on the desired segment length
Dim numSegments As Integer = _CirSegments 'CInt(Math.Ceiling(arcLength / (radius * segmentLengthFraction)))
' Calculate the angle increment for each segment
Dim angleIncrement As Double = sweepAngle / numSegments
' Create GraphicsPath to hold line segments
Dim path As New GraphicsPath()
Dim segments As New minMax
Dim lstsegments As New List(Of minMax)
' Add the first point of the arc to the path
path.AddLine(CSng(startX), CSng(startY), CSng(centerX + radius * Math.Cos(startAngle)), CSng(centerY + radius * Math.Sin(startAngle)))
' Add line segments approximating the arc
For i As Integer = 1 To numSegments
Dim angle As Double = startAngle + i * angleIncrement
Dim nextX As Double = centerX + radius * Math.Cos(angle)
Dim nextY As Double = centerY + radius * Math.Sin(angle)
segments = New minMax
segments.minx = CSng(path.GetLastPoint().X)
segments.miny = CSng(path.GetLastPoint().Y)
segments.maxx = CSng(nextX)
segments.maxy = CSng(nextY)
lstsegments.Add(segments)
path.AddLine(CSng(path.GetLastPoint().X), CSng(path.GetLastPoint().Y), CSng(nextX), CSng(nextY))
Next
Return lstsegments