troubles with cutafter
Hello, I went into some troubles with cutafter. Must have missed something obvious. \starttext \startMPpage path p[]; p1:= origin -- (100,0); p2:= (50,-50) -- (50,100); draw p1; draw p2; draw (p1 cutafter (p1 intersectionpoint p2)) withcolor red; \stopMPpage \stoptext Can someone explain me why the whole path p1 of this MWE is in red? I expected only its first half to be in red, and the whole line is. Thanks, Damien Thiriet
On 27 Oct 2020, at 14:06, Damien Thiriet
wrote: Hello,
I went into some troubles with cutafter. Must have missed something obvious.
Not so obvious: due to rounding/precision errors, the result of “intersectionpoint” is rarely the actual point. It finds a point “close to” the actual intersection of the two paths. The intersectionpoint calculation works by limited recursive bisection of the two paths, and thus it finds imprecise results in all but the most trivial cases. The result may be an actual point on p1 or p2, or on both, or even on neither. The better solution is to use intersectiontimes and subpath: draw subpath (0, xpart (p1 intersectiontimes p2)) of p1 withcolor red; Best wishes, Taco
participants (2)
-
Damien Thiriet
-
Taco Hoekwater