Check if two paths intersect in Metafun
Hi, list. I've got a question about paths and intersections. The following: \starttext \startMPpage path p[]; p[1] = fullcircle scaled 2cm; p[2] = unitsquare shifted (4cm,6cm); if (known (p[1] intersectionpoint p[2])): draw textext("yes"); else: draw textext("no"); fi; \stopMPpage \stoptext yields an error message: "The paths don't intersect". Is there a way to intercept this error message and trigger an action instead? Thank you in advance. Best regards, Jairo
Hi,
Le 25 déc. 2020 à 08:48, Jairo A. del Rio
a écrit : Hi, list. I've got a question about paths and intersections. The following:
\starttext \startMPpage path p[];
p[1] = fullcircle scaled 2cm; p[2] = unitsquare shifted (4cm,6cm);
if (known (p[1] intersectionpoint p[2])):
draw textext("yes");
else:
draw textext("no"); fi;
\stopMPpage \stoptext
yields an error message: "The paths don't intersect". Is there a way to intercept this error message and trigger an action instead? Thank you in advance.
Instead of using « intersectionpoint » use « Intersectiontimes », this will give you the « time » of the intersection of the two paths. If the paths do not intersect, than the value is (-1,-1). So you could do something like: pair checkintersec ; checkintersec := p[1] intersectiontimes p[2] ; If xpart(checkintersec) <> -1 : draw textext("yes »); else: draw textext(« non »); fi; Fabrice.
Best regards,
Jairo ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
participants (2)
-
Fabrice L
-
Jairo A. del Rio