For Programmers: Free Programming Magazines  


Home > Archive > Tex > October 2006 > Union of paths (metapost)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Union of paths (metapost)
Peng Yu

2006-10-30, 7:43 pm

Suppose I have two cycle paths. I want to clip the currentpicture to
the regions enclosed by these to paths. I'm wondering if it is possible
to do it simply in metapost as the seudo code shown below. If it is
possible, would you please let me know how to express the union of two
paths?

Thanks,
Peng

path p[];
p1 := ...;
p2 := ...;

draw something...

clip currentpicture to union of p1 and p2

Jean-Côme Charpentier

2006-10-30, 7:43 pm

Peng Yu a écrit :
> Suppose I have two cycle paths. I want to clip the currentpicture to
> the regions enclosed by these to paths. I'm wondering if it is possible
> to do it simply in metapost as the seudo code shown below. If it is
> possible, would you please let me know how to express the union of two
> paths?
>
> Thanks,
> Peng
>
> path p[];
> p1 := ...;
> p2 := ...;
>
> draw something...
>
> clip currentpicture to union of p1 and p2


Do you search for

p1..p2..cycle
or
p1--p2--cycle

depending what you want?

Jean-Côme Charpenntier
Peng Yu

2006-10-30, 7:43 pm



On Oct 27, 10:42 am, Jean-C=F4me Charpentier
<Jean-Come.Charpent...@wanadoo.fr> wrote:
> Peng Yu a =E9crit :
>
>
>
>
>
>
>
>
> p1..p2..cycle
> or
> p1--p2--cycle
>
> depending what you want?
>
> Jean-C=F4me Charpenntier

In my case, p1 and p2 are already disjointed cycles.

say

p1 :=3D (0,0)--(1,0)--(1,1)-(0,1)--cycle;
p2 :=3D p1 shifted (10,10);

tlhiv

2006-10-30, 7:43 pm

This is a "dirty hack", but I think it does what you want:

....
path p[];
p1:= (0,0)--(1,0)--(1,1)--(0,1)--cycle;
p2:= p1 shifted (10,10);
....
picture h[];
h1:=currentpicture;
clip currentpicture to p1;
h2:=currentpicture;
currentpicture:=h1;
clip currentpicture to p2;
draw h2;

These last 7 commands will essentially clip your picture twice and
redraw the first clipped picture (giving you the clipping you want).

I hope this helps.

--
Troy Henderson
Assistant Professor
Department of Mathematical Sciences
252 Thayer Hall
United States Military Academy
West Point, NY 10996
http://www.tlhiv.org

tlhiv

2006-10-30, 7:43 pm

Try this:

....
path p[];
p1:= (0,0)--(1,0)--(1,1)--(0,1)--cycle;
p2:= p1 shifted (10,10);
....
picture h[];
h1:=currentpicture;
clip currentpicture to p1;
h2:=currentpicture;
currentpicture:=h1;
clip currentpicture to p2;
draw h2;

These last 7 commands will essentially clip your picture twice and
redraw the first clipped picture (giving you the clipping you want).

I hope this helps.

--
Troy Henderson
Assistant Professor
Department of Mathematical Sciences
252 Thayer Hall
United States Military Academy
West Point, NY 10996
http://www.tlhiv.org

tlhiv

2006-10-30, 7:43 pm

Try this:

....
path p[];
p1:= (0,0)--(1,0)--(1,1)--(0,1)--cycle;
p2:= p1 shifted (10,10);
....
picture h[];
h1:=currentpicture;
clip currentpicture to p1;
h2:=currentpicture;
currentpicture:=h1;
clip currentpicture to p2;
draw h2;

These last 7 commands will essentially clip your picture twice and
redraw the first clipped picture (giving you the clipping you want).

I hope this helps.

--
Troy Henderson
Assistant Professor
Department of Mathematical Sciences
252 Thayer Hall
United States Military Academy
West Point, NY 10996
http://www.tlhiv.org

tlhiv

2006-10-30, 7:43 pm

Oops. Sorry for the multiple posts. Google groups caused this one.

Troy

tlhiv

2006-10-30, 7:43 pm

Try this:

....
path p[];
p1:= (0,0)--(1,0)--(1,1)--(0,1)--cycle;
p2:= p1 shifted (10,10);
....
picture h[];
h1:=currentpicture;
clip currentpicture to p1;
h2:=currentpicture;
currentpicture:=h1;
clip currentpicture to p2;
draw h2;

These last 7 commands will essentially clip your picture twice and
redraw the first clipped picture (giving you the clipping you want).

I hope this helps.

--
Troy Henderson
Assistant Professor
Department of Mathematical Sciences
252 Thayer Hall
United States Military Academy
West Point, NY 10996
http://www.tlhiv.org

tlhiv

2006-10-30, 7:43 pm

Try this:

....
path p[];
p1:= (0,0)--(1,0)--(1,1)--(0,1)--cycle;
p2:= p1 shifted (10,10);
....
picture h[];
h1:=currentpicture;
clip currentpicture to p1;
h2:=currentpicture;
currentpicture:=h1;
clip currentpicture to p2;
draw h2;

These last 7 commands will essentially will clip your picture twice and
redraw the first clipped picture (giving you the clipping you want).

I hope this helps.

--
Troy Henderson
Assistant Professor
Department of Mathematical Sciences
252 Thayer Hall
United States Military Academy
West Point, NY 10996
http://www.tlhiv.org

tlhiv

2006-10-30, 7:43 pm

Try this:

....
path p[];
p1:= (0,0)--(1,0)--(1,1)--(0,1)--cycle;
p2:= p1 shifted (10,10);
....
picture h[];
h1:=currentpicture;
clip currentpicture to p1;
h2:=currentpicture;
currentpicture:=h1;
clip currentpicture to p2;
draw h2;

These last 7 commands will essentially clip your picture twice and
redraw the first clipped picture (giving you the clipping you want).

I hope this helps.

--
Troy Henderson
Assistant Professor
Department of Mathematical Sciences
252 Thayer Hall
United States Military Academy
West Point, NY 10996
http://www.tlhiv.org

Dan

2006-10-30, 7:43 pm


tlhiv wrote:
> This is a "dirty hack", but I think it does what you want:
>
> ...
> path p[];
> p1:= (0,0)--(1,0)--(1,1)--(0,1)--cycle;
> p2:= p1 shifted (10,10);
> ...
> picture h[];
> h1:=currentpicture;
> clip currentpicture to p1;
> h2:=currentpicture;
> currentpicture:=h1;
> clip currentpicture to p2;
> draw h2;


That is essentially what is required, but that code is longer
(and more memory consuming) than it needs to be:

begingroup
save temppic; picture temppic;
temppic = currentpicture;
clip curentpicture to p1;
clip temppic to p2;
draw temppic;
endgroup

Pictures tend to be the most memory consuming aspect
of metapost (and metafont) processing. Three picture
variables in memory at once is usually avoidable. One
can even clip to an arbitrary array of paths with at most
three variables (two temporary):

%clip to an array p1, p2, ... p[n].
save temp_pic, temp_pic_;
picture temp_pic, temp_pic_;
temp_pic_ := nullpicture;
for k = 1 upto n:
temp_pic := currentpicture;
clip temp_pic to p[k];
addto temp_pic_ also temp_pic;
endfor
temp_pic:=nullpicture;
currentpicture := temp_pic_;
temp_pic_ := nullpicture;

In the package mfpic, a lot of the supporting meta*o*t
code produces intermediate pictures. I have hit metapost
and metafont memory limits often and learned
to frequently clean up temporary picture variables: assign
them to nullpicture whenever their contents are no
longer needed and/or initialize them inside a group with
a "save", so they disappear at the end of the group.


Dan

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com