Hi,(adsbygoogle = window.adsbygoogle || []).push({});

I'm working through thinkpython and there is an exercise which requires drawing flowers and arcs. I'm having some trouble understanding the arc function.

Here's the polyline code called from the above function:Code (Text):def arc(t, r, angle):

"""Draws an arc with the given radius and angle.

t: Turtle

r: radius

angle: angle subtended by the arc, in degrees

"""

arc_length = 2 * math.pi * r * abs(angle) / 360

n = int(arc_length / 4) + 1

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

lt(t, step_angle/2)

polyline(t, n, step_length, step_angle)

rt(t, step_angle/2)

Code (Text):def polyline(t, n, length, angle):

"""Draws n line segments.

t: Turtle object

n: number of line segments

length: length of each segment

angle: degrees between segments

"""

for i in range(n):

fd(t, length)

lt(t, angle)

I'm unsure about this part:

I'm guessing the purpose of n is to divide up the movements into separate iterations. How come it's set to arc_length / 4 + 1Code (Text):n = int(arc_length / 4) + 1

I'm guessing this is dividing up the total angle subtended by the arc into little bits which it gradually carves out....Code (Text):step_angle = float(angle) / n

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Algorithm for drawing an arc

Loading...

Similar Threads for Algorithm drawing |
---|

Insights Intro to Algorithms for Programming - Comments |

Python Verlet algorithm and Lorentz force trajectory |

C/++/# Is there a flaw in my longest common subsequence algorithm? |

C/++/# Finding duplicates algorithm |

Perceptron algorithm initial vector |

**Physics Forums | Science Articles, Homework Help, Discussion**