On MetaPost, I can use p intersectionpoint q to get a intersection point. But It will only return one point. How can I get all intersection points?
Asked
Active
Viewed 1,686 times
1 Answers
18
Taken from http://www.tug.org/pipermail/metapost/2008-October/001469.html with a number of changes to make the code more robust and general:
beginfig(1)
path p,q,r;
p := fullcircle xscaled 72 yscaled 36 shifted (10cm, 10cm);
q := fullcircle xscaled 36 yscaled 72 shifted (10cm, 10cm);
r := p;
draw p withcolor green;
draw q withcolor red;
n = 0;
forever:
r := r cutbefore q;
exitif length cuttings = 0;
r := subpath(epsilon, length r) of r;
z[n] = point 0 of r;
fill fullcircle scaled 2 shifted z[n] withcolor blue;
n := n + 1;
endfor;
endfig;
end
In practice one finds the first intersection, then cuts one of the two paths just after the intersection, and go on finding the next intersections.
Thruston
- 42,268
Marco Lombardi
- 1,415
-
1Afaik, you don't find the 'first one' on a path, you find one according to some algorithm but you may end up with more intersections before and after the first you have found. – gctwnl Mar 20 '20 at 23:28