[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";
beginfig(1)
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:
..ct*(cosd(i),sind(i))-p1
endfor
..(0,ct){left};
h2 := (0,0)
for i=1/16 step 1/16 until 1:
..(cc/2-a*sqrt((i*(cl/a)-(cl/a)/2)**2+((cc/a)**2-(cl/a)**2)/4),i*cl)
endfor;
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;
endfor
pickup pencircle scaled .8pt;
for i=1 upto 3:
draw h[i];
endfor
pickup pencircle scaled 4pt;
drawdot(q2);
endfig;
end
-------------------------------------------------------
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