Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated function arc() to be simpler #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions code/polygon.py
Expand Up @@ -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.
Expand Down