Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 6 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:

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 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
add comment

Your Answer

 
discard

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.