[metapost] Several intersection points

José Carlos Santos jcsantos at fc.up.pt
Mon Feb 24 13:31:52 CET 2014

Hi all,

Today I tried for the first time to obtain in MetaPost all intersection 
points of two lines. And I failed. :-( Here is the code:

----------------------- test.mp -----------------------

prologues := 3;
filenametemplate "%j.mps";
   numeric a,cc,cl,t[];
   pair p[],q[];
   path h[];
   a := 5mm;
   cc := 11a;
   cl := 10a;
   ct := 9.5a;
   p1 := (0,0);
   p2 := (cc,0);
   p3 := (cc,cl);
   p4 := (0,cl);
   h1 := (ct,0){up}
   for i=22.5 step 22.5 until 67.5:
   h2 := (0,0)
   for i=1/16 step 1/16 until 1:
   h3 := h2 reflectedabout ((p1+p2)/2,(p3+p4)/2);
   p5 := h1 intersectionpoint h2;
   for i=1 upto 2:
     (t[i],whatever) = h1 intersectiontimes h3;
     q[i] := point t[i] of h1;
   pickup pencircle scaled .8pt;
   for i=1 upto 3:
     draw h[i];
   pickup pencircle scaled 4pt;


The path h1 is a quarter of a circle and the path h3 is part of a 
hyperbola. As you can see, they intersect twice. I tried to define q1 
and q2 as these intersection points, but to MetaPost q1 = q2. That is, 
if I compile the file above, the line "drawdot(q2)" draws one of the 
intersection points, but if I replace it with "drawdot(q1)", then I get 
the _same_ point. What am I doing wrong?

Best regards,

Jose Carlos Santos

More information about the metapost mailing list