1. arc
Appends a counterclockwise circular arc to the current path.
1.2. Stack Effects
| Level | Object |
|---|---|
4 |
|
3 |
|
2 |
|
1 |
|
0 |
|
| Level | Object |
|---|---|
(empty) |
Stack cleared of operands |
1.3. Description
arc appends a counterclockwise arc of a circle to the current path. The arc has (x, y) as center, r as radius, ang1 as the angle from (x, y) to the first endpoint, and ang2 as the angle from (x, y) to the second endpoint.
Angles are measured in degrees counterclockwise from the positive x-axis of the current user coordinate system.
If there is a current point, arc includes a straight line segment from the current point to the first endpoint of the arc, then adds the arc into the current path. If the current path is empty, arc does not produce the initial straight line segment. In any event, the second endpoint of the arc becomes the new current point.
The curve produced is circular in user space. If user space is scaled non-uniformly (differently in x and y), arc will produce elliptical curves in device space.
1.5. Examples
newpath
200 200 50 0 360 arc
closepath
fill
newpath
200 200 75 0 180 arc
closepath
stroke
newpath
200 200 moveto % Move to center
200 200 100 0 45 arc % Draw arc from 0° to 45°
closepath % Line back to center
fill
newpath
150 150 50 45 135 arc % Upper-right quadrant
stroke
newpath
150 150 50 225 315 arc % Lower-left quadrant
stroke
1.6. Common Use Cases
1.6.1. Drawing Circular Shapes
/drawCircle {
% x y radius
/r exch def
/y exch def
/x exch def
newpath
x y r 0 360 arc
closepath
} def
200 200 50 drawCircle
fill
1.6.2. Creating Rounded Corners
/roundedRect {
% x y width height radius
/r exch def
/h exch def
/w exch def
/y exch def
/x exch def
newpath
x r add y moveto
x w add r sub y r 0 90 arc % Bottom-right
x w add y h add r sub r 90 180 arc % Top-right
x r add y h add r 180 270 arc % Top-left
x y r add r 270 360 arc % Bottom-left
closepath
} def
100 100 200 150 20 roundedRect
stroke
1.6.3. Drawing Gauges and Dials
/drawGauge {
% cx cy radius startAngle endAngle value
/val exch def
/endAng exch def
/startAng exch def
/r exch def
/cy exch def
/cx exch def
% Draw arc background
newpath
cx cy r startAng endAng arc
0.7 setgray
5 setlinewidth
stroke
% Draw value indicator
newpath
cx cy r startAng
startAng endAng startAng sub val mul add arc
1 0 0 setrgbcolor
stroke
} def
200 200 80 135 45 0.75 drawGauge
1.7. Common Pitfalls
| Angle Units - Angles are in degrees, not radians. A full circle is 360°, not 2π. |
200 200 50 0 6.28 arc % Wrong! Only draws ~6° of arc
200 200 50 0 360 arc % Correct: full circle
% For clockwise 90° arc from 0° to -90°:
200 200 50 0 -90 arc % Wrong! Draws 270° counterclockwise
200 200 50 0 -90 arcn % Correct: 90° clockwise
| Non-uniform Scaling - If the CTM has non-uniform scaling, arcs become elliptical. |
2 1 scale % Scale x by 2, y by 1
100 100 50 0 360 arc % Produces an ellipse, not a circle
1.8. Implementation Notes
-
Arcs are internally represented as one or more Bézier cubic curves
-
The conversion is accurate enough for faithful arc rendering
-
Programs using
pathforallwill seecurvetosegments -
Angles wrap around: 370° is equivalent to 10°
-
Negative angles are valid: -90° equals 270°
-
Zero radius creates a point (degenerate arc)
1.9. Error Conditions
| Error | Condition |
|---|---|
[ |
Path becomes too complex for implementation |
[ |
Fewer than 5 operands on stack |
[ |
Any operand is not a number |