[metapost] Several intersection points
José Carlos Santos
jcsantos at fc.up.pt
Mon Feb 24 17:22:48 CET 2014
On 24-02-2014 16:06, Daniel H. Luecking wrote:
>> for i=1 upto 2:
>> (t[i],whatever) = h1 intersectiontimes h3;
>> q[i] := point t[i] of h1;
> This simply applies the intersectiontimes operator to the same pair of paths twice.
> Of course it will produce the same result. Your only hope is to change the paths.
> The intersection of paths is described in "The Metafontbook",
> page 137. The intersectiontimes operator will compare each cubic
> Bezier segment of h1 with each segment of h2. If the intersection
> points are in different segments of one or the other path, then the
> point found will be in the first segment of h1 where they intersect.
> If you want to find a later intersection, you might then split the
> path (or reverse it if you are sure there are only 2 intersections):
> (whatever,t1) = h1 intersectiontimes h3;
> (whatever,t2) = (subpath (t1+eps, length h1) of h1) intersectiontimes h3;
> (whatever,t2) = (reverse h1) intersectiontimes h3;
> One has to move a little past t1 (say to t1+eps) to get a second
> intersection, since MP often finds an intersection at a starting point.
> Beware that intersections are sometimes not found if they occur (
> 1) at an endpoint or (2) where the paths are tangent. Also, if paths
> are simply very very close at some point (but not theoretically
> intersecting), intersectiontimes may think they do intersect.
> Finding multiple intersection points within a single Bezier
> segment can be done the same way, but they are not guaranteed to
> be in any particular order, so you have to examine the part
> before the first intersection found as well as the part after.
Thanks a lot. This was very useful.
Jose Carlos Santos
More information about the metapost