4 Jun 2012 18:00

Redefine ..

I am drawing 3D graphics, and many of my "points" are colors instead of pairs.  Of course, the colors are projected to pairs eventually, but I would like to define paths of colors directly with .. by doing something like

path p;
p:=(1,2,3)..(4,5,6)..(7,8,9);

I have a vardef P that transforms colors into pairs, and thus I can always just do

p:=P(1,2,3)..P(4,5,6)..P(7,8,9);

but I would like to be able to omit this P usage.  My attempt thusfar is

---
def pathnode primary a =
if color a:
P(a)
else:
a
fi;
enddef;

primarydef a .. b =
pathnode(a) .. pathnode(b)
enddef;
---

but this is not working.  I would appreciate any insight into how I might fix this so that I can use .. between pairs.

Troy Henderson

--
http://tug.org/metapost/
4 Jun 2012 19:08

Re: Redefine ..

On 4-6-2012 18:00, Troy Henderson wrote:
> I am drawing 3D graphics, and many of my "points" are colors instead of
> pairs.  Of course, the colors are projected to pairs eventually, but I
> would like to define paths of colors directly with .. by doing something
> like
>
> path p;
> p:=(1,2,3)..(4,5,6)..(7,8,9);
>
> I have a vardef P that transforms colors into pairs, and thus I can always
> just do
>
> p:=P(1,2,3)..P(4,5,6)..P(7,8,9);
>
> but I would like to be able to omit this P usage.  My attempt thusfar is
>
> ---
> def pathnode primary a =
>     if color a:
>        P(a)
>     else:
>        a
>     fi;
> enddef;
>
> primarydef a .. b =
>     pathnode(a) .. pathnode(b)
> enddef;
> ---
>
> but this is not working.  I would appreciate any insight into how I might
> fix this so that I can use .. between pairs.

def P (expr a) = (redpart a, greenpart a) enddef ;

def pathnode (expr a) =
if rgbcolor a :
P(a)
else :
a
fi
enddef ;

let normaldots = .. ;

primarydef a .. b =
pathnode(a) normaldots pathnode(b)
enddef;

draw (1,1,9) .. (2,1,6) .. (3,2,5) .. (4,1,5) ;

however, the next challenge is to catch a 'cycle'.

Hans

-----------------------------------------------------------------
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
--
http://tug.org/metapost/

4 Jun 2012 21:38

Re: Redefine ..

however, the next challenge is to catch a 'cycle'.

Indeed Hans.  Any thoughts on tackling that?

Troy
--
http://tug.org/metapost/
4 Jun 2012 22:34

Re: Redefine ..

On 4-6-2012 21:38, Troy Henderson wrote:
>>
>> however, the next challenge is to catch a 'cycle'.
>>
>
> Indeed Hans.  Any thoughts on tackling that?

No at this moment ... I tried a show on the argument but that somewhat
confusing. Probably best is to have a new symbol

def P (expr a) = (redpart a, greenpart a) enddef ;

def pathnode (expr a) =
if rgbcolor a :
P(a)
else :
a
fi
enddef ;

color threeDcycle ; threeDcycle := (4096,-4096,4096) ;

primarydef a .!. b =
if b = threeDcycle :
pathnode(a) .. cycle
else :
pathnode(a) .. pathnode(b)
fi
enddef;

draw (1,1,9) .!. (2,1,6) .!. (3,2,5) .!. (4,1,5) .!. threeDcycle ;

Hans

-----------------------------------------------------------------
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
--
http://tug.org/metapost/

5 Jun 2012 14:25

Re: Redefine ..

Hi,

HH> however, the next challenge is to catch a 'cycle'.
TH> Indeed Hans.  Any thoughts on tackling that?
[...]
HH> Probably best is to have a new symbol
[...]
HH> draw (1,1,9) .!. (2,1,6) .!. (3,2,5) .!. (4,1,5) .!. threeDcycle ;

Pretty neat. :)

Still, there remains a little bit more difficult challenge:
to allow tensions in path expressions. And curly braces...

I believe that the redefining of the "horizontal colon" is
a road to nowhere. The MF/MP lingo is too weak. It does
not allow for introducing "private" structures which
would provide a real solution.

First of all, tuples are limited to 2-tuple
(pair), 3-tuple (RGB color), 4-tuple (CMYK color),
and 6-tuple (transform), coordinates of each accessed
differently.

You are not allowed to define your own tuple -- indexed
variables cannot be used equivalently as a components
of expressions.

And paths are one level above tuples.

What one would actually need is to define a structure
corresponding to 3D path and project it into 2D space.
This is clearly impossible if one wants to preserve
the "syntactic sugar" of MF/MP.

All in all, I'd vote for Troy's first attempt:
to define 3D --> 2D function and apply it to every node.

Good luck -- cheers -- Jacko

Cheers -- Jacko

--

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bogus\l{}aw Jackowski: B_Jackowski <at> GUST.ORG.PL
----------------------------------------------------------------
Hofstadter's Law: It always takes longer than you expect, even
when you take into account Hofstadter's Law.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

--
http://tug.org/metapost/

5 Jun 2012 17:12

Re: Redefine ..

I mistakenly managed somehow to send this mail twice -- sorry for the
mess.

Cheers -- Jacko

--

--
BOP s. c.
ul. Bora-Komorowskiego 24, 80-377 Gdansk, Poland
tel. (+48 58) 553 46 59,  fax (+48 58) 511 03 81
bop <at> bop.com.pl, http://www.bop.com.pl
--
http://tug.org/metapost/

5 Jun 2012 16:58

Re: Redefine ..

Hi,

HH> however, the next challenge is to catch a 'cycle'.
TH> Indeed Hans.  Any thoughts on tackling that?
[...]
HH> Probably best is to have a new symbol
[...]
HH> draw (1,1,9) .!. (2,1,6) .!. (3,2,5) .!. (4,1,5) .!. threeDcycle ;

Pretty neat. :)

Still, there remains a little bit more difficult challenge:
to allow tensions in path expressions. And then -- curly braces...

I believe that the redefining of the "horizontal colon" is
a road to nowhere. The MF/MP lingo is too weak. It does
not allow for introducing "private" structures.

First of all, tuples are limited to 2-tuple
(pair), 3-tuple (RGB color), 4-tuple (CMYK color), and 6-tuple
(transform), coordinates of each accessed differently.

You are not allowed to define your own tuple and indexed
variables cannot be used equivalently as components
of expressions. And paths are one level above tuples.

What one would actually need is to define a structure
corresponding to 3D path and project it into 2D space.
This is clearly impossible if one wants to preserve
the "syntactic sugar" of MF/MP.

All in all, I'd vote for Troy's inital attempt. i.e.,
the defining of a  3D --> 2D function and apply it to every node.

Good luck -- cheers -- Jacko

Cheers -- Jacko

--

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bogus\l{}aw Jackowski: B_Jackowski <at> GUST.ORG.PL
----------------------------------------------------------------
Hofstadter's Law: It always takes longer than you expect, even
when you take into account Hofstadter's Law.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

--
http://tug.org/metapost/

5 Jun 2012 17:09

Re: Redefine ..

All in all, I'd vote for Troy's inital attempt. i.e.,
the defining of a  3D --> 2D function and apply it to every node.

Well, ultimately, I would like to see this as part of MetaPost itself.  It would be nice if MetaPost could handle 3D (perspective and orthographic, but AT LEAST orthographic projections) internally, and I am trying to develop code for Taco to be able to implement.

Luís Gonçalves (Featpost) and I have discussed this, and it is clear that a 3D implementation should, at least, provide paths of triplets (which is not currently available).  The technique that I have been using where I simply construct paths like

p:=P(1,2,3)..P(4,5,6)..P(7,8,9);

is the only way that I have been able to draw 3D paths, although the paths are not truly 3D (in that they have already been projected), and thus any manipulation in 3D cannot be performed.

Troy
--
http://tug.org/metapost/
6 Jun 2012 18:11

Re: Redefine ..

Le 04/06/2012 18:00, Troy Henderson a écrit :
> I am drawing 3D graphics, and many of my "points" are colors instead of
> pairs.  Of course, the colors are projected to pairs eventually, but I
> would like to define paths of colors directly with .. by doing something like
>
> path p;
> p:=(1,2,3)..(4,5,6)..(7,8,9);
>
> I have a vardef P that transforms colors into pairs, and thus I can always
> just do
>
> p:=P(1,2,3)..P(4,5,6)..P(7,8,9);
>
> but I would like to be able to omit this P usage.  My attempt thusfar is
>
> ---
> def pathnode primary a =
>     if color a:
>        P(a)
>     else:
>        a
>     fi;
> enddef;
>
> primarydef a .. b =
>     pathnode(a) .. pathnode(b)
> enddef;
> ---
>
> but this is not working.  I would appreciate any insight into how I might
> fix this so that I can use .. between pairs.
>
>
> Troy Henderson
>
>
> --
> http://tug.org/metapost/

A dirty workaround could be to scan color-path expressions looking for
colors, then prefixing them with P (thus turning
"(1,2,3)..(4,5,6)..(7,8,9)" into "P(1,2,3)..P(4,5,6)..P(7,8,9)"). Here is
a naive attempt.

vardef P expr clr=
(redpart clr, greenpart clr)
enddef;

vardef map  <at> # expr pth=
string fun, aux, res, chr, acc;
numeric len;
fun:=str  <at> #;
aux:=pth;
len:=length aux;
res:="";
forever:
exitif len=0;
chr:=substring(0, 1) of aux;
aux:=substring(1, len) of aux;
len:=len-1;
if chr<>"(":
res:=res&chr;
else: % we look for the next ")" occurrence
acc:=chr;
forever:
exitif len=0;
chr:=substring(0, 1) of aux;
aux:=substring(1, len) of aux;
len:=len-1;
acc:=acc&chr;
exitif chr=")";
endfor
if color scantokens acc:
res:=res&fun&acc;
else:
res:=res&acc;
fi
fi
endfor
show res;
scantokens res
enddef;

draw map P "(0, 1, 2) .. controls (3, 4, 5) .. {(6, 7, 8)} (9, 0) .. cycle";

>> "P(0, 1, 2) .. controls P(3, 4, 5) .. {P(6, 7, 8)} (9, 0) .. cycle"

Regards,
Laurent Méhats

--
http://tug.org/metapost/

6 Jun 2012 19:04

Re: Redefine ..

Regards,
Laurent Méhats

Thank you Laurent.
--
http://tug.org/metapost/

Gmane