Math's Trig Versus Basic's Trig Functions
#20
Updated drawArc and drawPieSlice to match Trig Angles start arcs in Radian units:

Test code for routines:
Code: (Select All)
Option _Explicit
_Title "Arc New 2022-09-28" 'b+ 2022-09-28

Screen _NewImage(800, 600, 32)
_ScreenMove 250, 50

Dim start, measure, r
Do
    r = Rnd * 150 + 1
    start = Rnd * _Pi(2)
    measure = Rnd * _Pi(2)
    drawArc 400, 300, r + 20, start, measure, &HFFFFFF00
    drawPieSlice 400, 300, r, start, measure, &HFF0000FF
    Color &HFFFFFF00
    Print "Start Angle:"; _R2D(start) \ 1;
    Color &HFF0000FF
    Print "Degrees for Arc Angle:"; _R2D(measure) \ 1; "Degrees"
    Color &HFFFFFFFF
    Print "Pie Slice Radius:"; r \ 1; "  Arc Radius:"; r \ 1 + 20
    Sleep
    Cls
Loop

'Arc New 2022-09-28 independent of constants and routines
Sub drawArc (xc, yc, radius, rStart, rMeasure, colr As _Unsigned Long)
    ' xc, yc Center for arc circle
    ' rStart is the Radian Start Angle, use _D2R for conversion from Degrees to Radians
    ' rMeasure is the measure of Arc in Radain units, use _D2R for conversion from Degrees to Radians
    ' Arc will start at rStart and go clockwise around for rMeasure Radians

    Dim rEnd, stepper, a, x, y

    rEnd = rStart + rMeasure
    stepper = 1 / radius ' the bigger the radius the smaller  the steps
    For a = rStart To rEnd Step stepper
        x = xc + radius * Cos(a)
        y = yc + radius * Sin(a)
        If a > rStart Then Line -(x, y), colr Else PSet (x, y), colr
    Next
End Sub

'Arc New 2022-09-28 independent of constants and routines
Sub drawPieSlice (xc, yc, radius, rStart, rMeasure, colr As _Unsigned Long)
    ' xc, yc Center for arc circle
    ' rStart is the Radian Start Angle, use _D2R for conversion from Degrees to Radians
    ' rMeasure is the measure of Arc in Radain units, use _D2R for conversion from Degrees to Radians
    ' Arc will start at rStart and go clockwise around for rMeasure Radians

    Dim rEnd, stepper, a, x, y

    rEnd = rStart + rMeasure
    Line (xc, yc)-(xc + radius * Cos(rStart), yc + radius * Sin(rStart)), colr
    Line (xc, yc)-(xc + radius * Cos(rEnd), yc + radius * Sin(rEnd)), colr
    stepper = 1 / radius ' the bigger the radius the smaller  the steps
    For a = rStart To rEnd Step stepper
        x = xc + radius * Cos(a)
        y = yc + radius * Sin(a)
        If a > rStart Then Line -(x, y), colr Else PSet (x, y), colr
    Next
    Paint (xc + .5 * radius * Cos(rStart + .5 * rMeasure), yc + .5 * radius * Sin(rStart + .5 * rMeasure)), colr, colr
End Sub
b = b + ...
Reply


Messages In This Thread
RE: Math's Trig Versus Basic's Trig Functions - by bplus - 09-28-2022, 04:23 PM



Users browsing this thread: 13 Guest(s)