From e726ebda31272d8c63ba2d13910d3159770ad0f5 Mon Sep 17 00:00:00 2001 From: abhitrueprogrammer <67090539+abhitrueprogrammer@users.noreply.github.com> Date: Wed, 23 Mar 2022 14:05:45 +0530 Subject: [PATCH] Updating function arc() to be simpler Updated arc() to just model a circle but only till the angle required. This approach is simpler than using an obscure formula [n = int(arc_length/3) +1] and doesn't even cause the turtle to be a few pixels away from true destination --- code/polygon.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/code/polygon.py b/code/polygon.py index 2eb5c97..2603d13 100644 --- a/code/polygon.py +++ b/code/polygon.py @@ -56,17 +56,13 @@ def arc(t, r, angle): r: radius angle: angle subtended by the arc, in degrees """ - arc_length = 2 * math.pi * r * abs(angle) / 360 - n = int(arc_length / 4) + 3 - step_length = arc_length / n - step_angle = float(angle) / n - - # making a slight left turn before starting reduces - # the error caused by the linear approximation of the arc - t.lt(step_angle/2) - polyline(t, n, step_length, step_angle) - t.rt(step_angle/2) - + resolution = 69 + total_circumference = 2 * math.pi * r #circumference of a circle with same radius as the arc + segment_length = total_circumference/ resolution + LT_angle = 360/resolution + ratio = angle/360 #ratio that the arc is of a circle with the same radius as the arc + resolution = int(resolution * ratio) + polyline(t, resolution, segment_length, LT_angle) def circle(t, r): """Draws a circle with the given radius.