Qu

arc

Builtin index · Plotting

arc(cx, cy, r, from, to)

Input: cx, cy, r, from, to · Output: no output

What it is

Draws part of a circle, as an open stroke. cx and cy (numbers) are the centre, in data coordinates; r (number, positive — a zero or negative radius is an error) is the radius, applied as the same figure to both axes, so a panel whose x and y scales differ draws an ellipse rather than a round arc — a square canvas is what makes it round, not axis equal, which only equalises the ranges; from (number, degrees) is the angle the sweep starts at, measured counterclockwise from the positive x axis, so 0 is the three-o'clock position; to (number, degrees) is the angle it ends at, and a to smaller than from sweeps clockwise instead. Optional segments= (number, default 128) is how many straight pieces approximate the curve, and rotate= (number, degrees) turns the whole arc about its centre. Unlike circle, an arc is open — it renders as a stroke (color=/width=/dash=), not a fillable shape.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
arc(cx, cy, r, from, to)
cx numbercx and cy (numbers) are the centre, in data coordinates.
cy numbercx and cy (numbers) are the centre, in data coordinates.
r numberr (number, positive — a zero or negative radius is an error) is the radius, applied as the same figure to both axes, so a panel whose x and y scales differ draws an ellipse rather than a round arc — a square canvas is what makes it round, not axis equal, which only equalises the ranges.
from numberfrom (number, degrees) is the angle the sweep starts at, measured counterclockwise from the positive x axis, so 0 is the three-o'clock position.
to numberto (number, degrees) is the angle it ends at, and a to smaller than from sweeps clockwise instead.
no outputDraws part of a circle, as an open stroke. Optional segments= (number, default 128) is how many straight pieces approximate the curve, and rotate= (number, degrees) turns the whole arc about its centre. Unlike circle, an arc is open — it renders as a stroke (color=/width=/dash=), not a fillable shape.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

# A square canvas, so that equal ranges really are equal scales and the

# circle below comes out round. Without it the figure would render an

# ellipse while the paragraph above it explained how to avoid one.

figure_size(560, 560)
xlim(-2, 2)
ylim(-2, 2)
axis equal
circle(0, 0, 1, color = "royalblue", fill = "royalblue")
ellipse(0, 0, 1.6, 0.7, color = "crimson", rotate = 30)
arc(0, 0, 1.3, 0, 120, color = "seagreen", width = 2)
polygon([0.8, 1.6, 1.2], [-1.6, -1.6, -0.9], color = "purple", fill = "plum")
rectangle(-1.8, -1.8, -1.2, -1.2, color = "orange")
rect(1.0, -1.8, 1.8, -1.2, color = "teal")
point(0, 1.9)
-2.0 -1.5 -1.0 -0.5 0 0.5 1.0 1.5 2.0 -2.0 -1.5 -1.0 -0.5 0 0.5 1.0 1.5 2.0 (0, 1.9)

from plotting

How it works

── shapes ────────────────────────────────────────────── circle(cx, cy, r), ellipse(cx, cy, rx, ry), arc(cx, cy, r, from_deg, to_deg), polygon(xs, ys). All are sampled in DATA space and mapped through the axis transform, so a circle stays a circle when the axes are equal and becomes the correct ellipse when they are not. Emitting an SVG <circle> at a pixel radius would be simpler and would draw the wrong shape on any panel whose scales differ -- which is most of them. segments= controls the sampling; 128 is smooth at any figure size a paper uses and cheap enough not to think about.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.