1. arcto
Appends an arc defined by two tangent lines and returns the tangent points.
1.2. Stack Effects
| Level | Object |
|---|---|
4 |
|
3 |
|
2 |
|
1 |
|
0 |
|
| Level | Object |
|---|---|
3 |
|
2 |
|
1 |
|
0 |
|
1.3. Description
arcto produces the same effect as arct. It also returns the two tangent point coordinates (xt1, yt1) and (xt2, yt2) in user space.
The arc is defined by: 1. A tangent line from the current point (x0, y0) to (x1, y1) 2. A tangent line from (x1, y1) to (x2, y2) 3. A radius r
The arc is tangent to both lines, and the tangent points are returned on the stack.
1.5. Examples
newpath
100 100 moveto
200 100 200 200 30 arcto
% Stack now has: xt1 yt1 xt2 yt2
% xt1, yt1 is where arc starts on first line
% xt2, yt2 is where arc ends on second line
pop pop pop pop % Discard tangent points
stroke
/drawMarkerAtTangents {
% x1 y1 x2 y2 radius
arcto
% Mark second tangent point
gsave
newpath
0 5 rlineto
5 0 rlineto
0 -5 rlineto
closepath
fill
grestore
% Mark first tangent point
gsave
newpath
0 5 rlineto
5 0 rlineto
0 -5 rlineto
closepath
fill
grestore
} def
newpath
100 100 moveto
200 100 200 200 25 drawMarkerAtTangents
stroke
/arcLength {
% Returns approximate arc length
% x1 y1 x2 y2 radius -> length
arcto
% Calculate distance between tangent points
/yt2 exch def /xt2 exch def
/yt1 exch def /xt1 exch def
xt2 xt1 sub dup mul
yt2 yt1 sub dup mul
add sqrt
} def
newpath
100 100 moveto
200 100 200 200 30 arcLength
% Returns approximate arc length
1.6. Common Use Cases
1.6.1. Precise Corner Construction
/preciseRoundedCorner {
% Uses tangent points for exact positioning
% x1 y1 x2 y2 radius
arcto
% Save tangent points for later use
/yt2 exch def /xt2 exch def
/yt1 exch def /xt1 exch def
% Could use tangent points for:
% - Adding decorations at corners
% - Calculating dimensions
% - Placing text labels
} def
1.6.2. Creating Annotated Diagrams
/annotatedArc {
% x1 y1 x2 y2 radius label
/label exch def
/r exch def
/y2 exch def /x2 exch def
/y1 exch def /x1 exch def
% Draw the arc and get tangent points
x1 y1 x2 y2 r arcto
/yt2 exch def /xt2 exch def
/yt1 exch def /xt1 exch def
% Place label at midpoint of arc
gsave
xt1 xt2 add 2 div yt1 yt2 add 2 div moveto
label show
grestore
} def
newpath
100 100 moveto
200 100 200 200 30 (Arc) annotatedArc
1.6.3. Measuring Corner Geometry
/measureCorner {
% Returns corner dimensions
% x1 y1 x2 y2 radius -> setback1 setback2 arclen
5 copy arcto
% Calculate setbacks (distances from corner to tangent points)
/yt2 exch def /xt2 exch def
/yt1 exch def /xt1 exch def
% Setback on first line
currentpoint
/y0 exch def /x0 exch def
xt1 x0 sub dup mul yt1 y0 sub dup mul add sqrt
% Setback on second line (from x1,y1 to xt1,yt1)
xt1 5 index sub dup mul yt1 4 index sub dup mul add sqrt
% Arc length (approximate)
xt2 xt1 sub dup mul yt2 yt1 sub dup mul add sqrt
} def
1.7. Common Pitfalls
Stack Management - arcto leaves four values on the stack. Remember to pop them if not needed.
|
newpath
100 100 moveto
200 100 200 200 20 arcto
% Stack has 4 extra values!
stroke % May cause typecheck error
Use When You Need Tangent Points - If you don’t need the tangent points, use arct instead for cleaner stack management.
|
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
-
Identical path construction to
arct -
Returns tangent points in user space coordinates
-
Tangent points are on the original tangent lines, not the arc
-
Useful for geometric calculations and annotations
-
Cannot be encoded in user paths
1.11. See Also
-
arct- Arc by tangent (no tangent point return) -
arc- Counterclockwise circular arc -
arcn- Clockwise circular arc -
currentpoint- Get current point