TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 8 down vote accepted

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:


  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;
    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;



In practice one finds the first intersection, then cuts one of the two pats just after the intersection, and go on finding the next intersections.

share|improve this answer
Great! I Will test it. – 比尔盖子 Oct 28 '12 at 2:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.