Post by bplus on Apr 4, 2024 0:54:46 GMT
this is code for drawing an arc from point 1 (x1, y1) to point 2 (x2, y2) looking at point 2 from point 1 the origin of the radius of arc will be on the left side of line p1p2 and the arc with be on the right side. the central angle of the iso triangle is given by ra (radian angle).
here is a demo points 300, 300 to 500, 300 yellow
and 500, 300 to 300, 300 orange
and points 400, 200 to 400, 400 cyan
and 400, 400 to 400, 200 blue
here is a demo points 300, 300 to 500, 300 yellow
and 500, 300 to 300, 300 orange
and points 400, 200 to 400, 400 cyan
and 400, 400 to 400, 200 blue
_Title "DrawArcs" ' b+ 2024-03-31
Screen _NewImage(800, 600, 32)
For a = .0025 To _Pi(1) Step .001
Cls
DrawArc 300, 300, 500, 300, a, &HFFFFFF00
DrawArc 500, 300, 300, 300, a, &HFFFF8800
DrawArc 400, 200, 400, 400, a, &HFF0088FF
DrawArc 400, 400, 400, 200, a, &HFF0000FF
_Display
_Limit 500
Next
Sub DrawArc (x1, y1, x2, y2, ra, c~&)
' this sub draws an arc between p1 = (x1, y1) and p2 = (x2, y2)
' p1 to p2 is chord of arc at the angle a
' as you stand at p1 and look to p2 the arc is drawn on your right.
' ra is the radian angle of the apex of iso triangle or central angle of arc
' this does not like ra close to 0, when dist = 200 ra > .0023
' as ra ===> 0 x0, y0 ===> infinity and the arc ===> straight line segment
dist = _Hypot(x1 - x2, y1 - y2) ' dist between p1 and p2
a = _Atan2(y2 - y1, x2 - x1) ' p2 is at angle a to p1
radius = .5 * dist / Sin(.5 * ra) ' radius of the arc
mx = (x1 + x2) / 2: my = (y1 + y2) / 2 ' midpoint of segment p1 p2
'this locates the origin of arc on left of direction p1 to p2
x0 = mx + radius * Cos(.5 * ra) * Cos(a - _Pi / 2)
y0 = my + radius * Cos(.5 * ra) * Sin(a - _Pi / 2)
' this draws the arc on the right side of p1 to p2 direction
a1 = _Atan2(my - y0, mx - x0)
a2 = a1 + ra / 2
a3 = a1 - ra / 2
' acrcs have to be draw clockwise so we have to start at lesser angle
If a2 < a3 Then starta = a2: stopa = a3 Else starta = a3: stopa = a2
arc x0, y0, radius, starta, stopa, c~&
End Sub
Sub arc (x, y, r, raStart, raStop, c As _Unsigned Long) ' this does not check raStart and raStop like arcC does
'x, y origin, r = radius, c = color
'raStart is first angle clockwise from due East = 0 degrees
' arc will start drawing there and clockwise until raStop angle reached
Dim al, a
If raStop < raStart Then
arc x, y, r, raStart, _Pi(2), c
arc x, y, r, 0, raStop, c
Else
' modified to easier way suggested by Steve
'Why was the line method not good? I forgot.
al = _Pi * r * r * (raStop - raStart) / _Pi(2)
For a = raStart To raStop Step 1 / al
PSet (x + r * Cos(a), y + r * Sin(a)), c
Next
End If
End Sub