[metapost] intersectiontimes peculiarity

Troy Henderson thenders at gmail.com
Wed Apr 24 11:27:27 CEST 2013


I've read Knuth's explanation of how "intersectiontimes" works when two
paths intersect in multiple points (in Chapter 14 of the METAFONTbook), but
I cannot seem to figure out how to FORCE lexicographic ordering of the
intersection times.

For example, if paths p and q intersect in multiple points, I would like
to, somehow, have

(s,whatever) = q intersectiontimes p;

return the "first" (i.e., smallest "time") for q in which q and p
intersect.  This is illustrated in the code below (which generates the
attached figure).

Notice that q intersects p at times (and these times are for q) 0.07144,
0.35716, 0.64287, and 0.92859 which correspond to the points (1,-5),
(1,-3), (1,-1) and (1,1), respectively.  However, the command

(s,whatever) = q intersectiontimes p;

returns the last (namely 0.92859) time for q instead of the first (namely
0.07144) time for the intersection.  Is there a way to FORCE "q
intersectiontimes p" to always return the smallest time for q?

Thanks in advance,

Troy

--

path p,q,r;
p:=(0,0){up}..(1,1){right}..(4,-2){down}..(1,-5){left}..(0,-4){up}..(2,-2){up}..cycle;
q:=(1,-5.5)--(1,1.5);
r:=subpath (0,1/4) of q;

numeric s,t;
(s,whatever)=q intersectiontimes p;
(t,whatever)=r intersectiontimes p;

beginfig(0);
    u:=28;
    draw p scaled u;
    drawarrow subpath (0,1/6) of q scaled u withcolor red;
    drawarrow subpath (1/6,1/2) of q scaled u withcolor red;
    drawarrow subpath (1/2,5/6) of q scaled u withcolor red;
    draw subpath (5/6,1) of q scaled u withcolor red;
    fill fullcircle scaled 4 shifted (point s of q scaled u) withcolor blue;
    fill fullcircle scaled 4 shifted (point t of r scaled u) withcolor
(7/8*green);
endfig;

end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/metapost/attachments/20130424/d3ece8fc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.pdf
Type: application/pdf
Size: 2822 bytes
Desc: not available
URL: <http://tug.org/pipermail/metapost/attachments/20130424/d3ece8fc/attachment.pdf>


More information about the metapost mailing list