1. arct
Appends an arc defined by two tangent lines 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
arct appends an arc of a circle to the current path, possibly preceded by a straight line segment. The arc is defined by a radius r and two tangent lines.
The tangent lines are: 1. From the current point (x0, y0) to (x1, y1) 2. From (x1, y1) to (x2, y2)
If the current point is undefined, arct executes the [nocurrentpoint] error.
The center of the arc is located at distance r perpendicular to both tangent lines, within the inner angle between them. The arc begins at the first tangent point (xt1, yt1) on the first tangent line, and ends at the second tangent point (xt2, yt2) on the second tangent line.
Before constructing the arc, arct adds a straight line from the current point to (xt1, yt1), unless those points are the same. The point (xt2, yt2) becomes the new current point.
If the two tangent lines are collinear, arct merely appends a straight line from (x0, y0) to (x1, y1).
1.5. Examples
newpath
100 100 moveto
200 100 200 200 20 arct % Round corner at (200, 100)
200 200 lineto
stroke
/roundedRect {
% x y width height radius
/r exch def
/h exch def
/w exch def
/y exch def
/x exch def
newpath
x y r add moveto
x y x w add y r arct
x w add y x w add y h add r arct
x w add y h add x y h add r arct
x y h add x y r arct
closepath
} def
50 50 200 150 25 roundedRect
stroke
newpath
50 200 moveto
100 200 100 100 30 arct % Smooth transition at (100, 200)
100 100 200 100 30 arct % Smooth transition at (100, 100)
200 100 lineto
stroke
1.6. Common Use Cases
1.6.1. Rounding Sharp Corners
/roundCorner {
% x1 y1 x2 y2 radius
arct
} def
newpath
100 100 moveto
200 100 200 200 15 roundCorner
200 200 100 200 15 roundCorner
100 200 100 100 15 roundCorner
closepath
stroke
1.6.2. Creating UI Elements
/roundedButton {
% x y width height radius
/r exch def
/h exch def
/w exch def
/y exch def
/x exch def
newpath
x y moveto
x w add y x w add y h add r arct
x w add y h add x y h add r arct
x y h add x y r arct
x y x w add y r arct
closepath
0.9 0.9 0.9 setrgbcolor fill
0 0 0 setrgbcolor stroke
} def
100 100 150 40 10 roundedButton
1.6.3. Smooth Path Connections
/connectWithArc {
% Creates smooth connection between line segments
% x1 y1 x2 y2 x3 y3 radius
/r exch def
/y3 exch def /x3 exch def
/y2 exch def /x2 exch def
/y1 exch def /x1 exch def
x1 y1 lineto
x2 y2 x3 y3 r arct
} def
newpath
50 50 moveto
100 50 150 100 200 100 20 connectWithArc
stroke
1.7. Common Pitfalls
Requires Current Point - arct needs a current point to define the first tangent line.
|
newpath
100 100 200 100 20 arct % Error: nocurrentpoint
| Collinear Points - If the three points are collinear, no arc is created, just a straight line to (x1, y1). |
100 100 moveto
200 100 300 100 20 arct % All on same line, no arc
| Radius Too Large - Very large radii relative to the angle may produce unexpected results or hit numerical limits. |
Perfect for UI Corners - arct is ideal for creating rounded corners in user interfaces and technical drawings where corners are defined by intersecting lines.
|
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
Path becomes too complex for implementation |
[ |
Current path is empty (no current point defined) |
[ |
Fewer than 5 operands on stack |
[ |
Any operand is not a number |
[ |
Degenerate tangent configuration |
1.9. Implementation Notes
-
Arc is circular in user space
-
Non-uniform scaling produces elliptical results
-
Internally converted to Bézier curves
-
The connecting line from current point is automatic
-
Tangent points are calculated but not returned (use
arctofor that)
1.10. Performance Considerations
-
Slightly more complex than
arcdue to tangent calculations -
Very efficient for creating rounded corners
-
Single operation replaces manual tangent point calculation