## Arcs

- XLogo library of procedures

This library of procedures draws arcs in various manners. They are used by programs throughout this site including many of the shape procedures. They can be copied and pasted into the Editor window as usual.

I prefer not to use the Arc primitive directly. It is difficult to 'read', uses three arguments, often requires the Minus primitive, and uses absolute headings which are not very logo like. Instead use rArc (relarive Arc).

rArc
Draw a clockwise arc relative to the turtles heading. The turtle turns to face the end of the arc. Both :Angle and :Radius arguments are positive. Putting the angle first makes turtle movements easier to follow.
Used in many programs instead of primitive Arc.

# clockwise arc drawn relative to turtle heading
End

Arch
The Arch procedure draws a symmetrical arch relative to the turtle heading. The turtle is left unmoved. Both :Angle and :Radius arguments are positive.

# symmetrical arc drawn relative to turtle heading
End

LeftArc (also see RightArc)
Move turtle along a curved arc to the left. Similar to Left with a radius of zero. Both :Angle and :Radius arguments must be positive.

# arc drawn relative to turtle position, angle & radius positive
PenUp Right 90 Back :Radius Left :Angle
End

RightArc (also see LeftArc)
Move turtle along a curved arc to the right. Similar to Right with a radius of zero. Both :Angle and :Radius arguments must be positive.

# arc drawn relative to turtle position, angle & radius positive
Right :Angle Forward :Radius Right 90 PenDown
End

'Full' Arc Procedures

The above Arcs are simplified for use as library procedures in programs on this site. Below are more complete Arc procedures which allow for negative angles and angles greater than 360 degrees etc.

rArc
Allow for anti-clockwise arcs if :Angle is negative.

# arc drawn relative to turtle heading
If :Angle <0
Right :Angle
End

Or

# arc drawn relative to turtle heading
LocalMake "H1 ((Minus :Angle) +Abs :Angle) /-2
LocalMake "H2 ((Minus :Angle) -Abs :Angle) /-2
Right :Angle
End

Arch
Draw an arch behind the turtle if :Angle is negative.
Draw a circle if :Angle is greater than 360 degrees.

# symmetrical arc drawn relative to turtle heading
If (Absolute :Angle) <360 [
If :Angle <0
End

LeftArc (also see RightArc)
StopAll and show error message if :Radius is negative as incorrect arc will be drawn.
If :Angle is negative then similar to RightArc.
If the pen is up, no curve is drawn.

# arc drawn relative to turtle position
PenUp If :Angle <0
Left :Angle Forward :Radius Right 90]
PenDown
End

RightArc (also see LeftArc)
StopAll and error message if :Radius is negative as incorrect arc will be drawn.
If :Angle is negative then similar to LeftArc.
If the pen is up, no curve is drawn.

# arc drawn relative to turtle position
PenUp If :Angle <0
Right :Angle Forward :Radius Right 90]
PenDown
End

Curve

Arcs (and circles) cannot be filled using the FillPolygon primitive. They have to be drawn as a series of small steps. Here is a possible procedure to do this.

# curved arc drawn relative to turtle position
LocalMake "StepAngle :Angle/:Steps
Forward :StepSize/2
Repeat :Steps-1 [Right :StepAngle Forward :StepSize]
Right :StepAngle Forward :StepSize/2