All, I'm looking for a new idea for something I need to do. I typically create a path on a domain [-5,5] as follows, a arbitrary. Then I randomly reflect the path about and axis, a line, or maybe rotate it. The result is that parts of the path may lie outside a bounding window. % define linear function f vardef f(expr x)= a*x*x enddef; % define paths for functions f, g, and h, respectively path P; P:=(-5,f(-5)); for x=-5 step .1 until 5: P:=P--(x,f(x)); endfor; % initialize scale numeric u; 10u=w; % scale and draw graph P:=P scaled u; draw P withcolor blue; % clipping path path cpath; cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle; cpath:=cpath scaled 1u; % clip and save current picture picture pic; clip currentpicture to cpath; pic:=currentpicture; % erase currentpicture currentpicture:=nullpicture; Then I do some stuff I need to do and bring back the path at a later time with: draw pic; This works fine. However, what I need to do is somehow clip the path P to the bounding box, but retain the resulting cutpath in a path variable Q. That is, I need to cut off the parts of the path P that lie outside the bounding box cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle and store the clipped path in the path variable Q. The difficulty is I have no advance knowledge if the path P lies entirely inside the bounding box or if it escapes through one of the sides. Any hints, tips, etc., would be very appreciated. Thanks.
David Arnold wrote:
This works fine. However, what I need to do is somehow clip the path P to the bounding box, but retain the resulting cutpath in a path variable Q. That is, I need to cut off the parts of the path P that lie outside the bounding box cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle and store the clipped path in the path variable Q. The difficulty is I have no advance knowledge if the path P lies entirely inside the bounding box or if it escapes through one of the sides.
it all depends on what you want to do further on; - you can do some cutbefore and cutafter trickery, i.e. determine intersectionpoints with the edges of the bbox and do some cutting - if you just want the path back .. just ask for "pathpart pic" Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hans, I tried: % redraw line path q; q:=pathpart pic; drawdblarrow q withcolor blue; But it drew the clipping path. I wanted the part of the path inside the clipping path. Am I missing something in your directions? On Aug 7, 2005, at 2:56 PM, Hans Hagen wrote:
David Arnold wrote:
This works fine. However, what I need to do is somehow clip the path P to the bounding box, but retain the resulting cutpath in a path variable Q. That is, I need to cut off the parts of the path P that lie outside the bounding box cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle and store the clipped path in the path variable Q. The difficulty is I have no advance knowledge if the path P lies entirely inside the bounding box or if it escapes through one of the sides.
it all depends on what you want to do further on; - you can do some cutbefore and cutafter trickery, i.e. determine intersectionpoints with the edges of the bbox and do some cutting
- if you just want the path back .. just ask for "pathpart pic" Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
_______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
David Arnold wrote:
Hans,
I tried:
% redraw line path q; q:=pathpart pic; drawdblarrow q withcolor blue;
But it drew the clipping path. I wanted the part of the path inside the clipping path.
Am I missing something in your directions?
ok, here's the full solution ... \starttext \setupcolors[state=start] \startMPpage vardef lastpath (expr p) = save _p_ ; path _p_ ; _p_ := origin ; for i within p : if stroked i : _p_ := pathpart i ; fi ; endfor ; _p_ enddef ; vardef firstpath (expr p) = save _p_, _b_ ; path _p_ ; _p_ := origin ; boolean _b_ ; _b_ := false ; for i within p : if not _b_ : if stroked i : _b_ := true ; _p_ := pathpart i ; fi ; fi ; endfor ; _p_ enddef ; picture pic; pic := image( draw fullcircle scaled 5cm withpen pencircle scaled 5mm ; draw fullsquare scaled 2cm withpen pencircle scaled 5mm ; fill fullcircle scaled 1cm withpen pencircle scaled 5mm ; ) ; draw pic ; drawdblarrow lastpath (pic) withcolor blue ; drawdblarrow firstpath(pic) withcolor red ; \stopMPpage \stoptext ... suitable for submission to the wiki
On Aug 7, 2005, at 2:56 PM, Hans Hagen wrote:
David Arnold wrote:
This works fine. However, what I need to do is somehow clip the path P to the bounding box, but retain the resulting cutpath in a path variable Q. That is, I need to cut off the parts of the path P that lie outside the bounding box cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle and store the clipped path in the path variable Q. The difficulty is I have no advance knowledge if the path P lies entirely inside the bounding box or if it escapes through one of the sides.
it all depends on what you want to do further on; - you can do some cutbefore and cutafter trickery, i.e. determine intersectionpoints with the edges of the bbox and do some cutting
- if you just want the path back .. just ask for "pathpart pic" Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
_______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
_______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
-- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
David Arnold
-
Hans Hagen