On Fri, 30 Jun 2006, Idris Samawi Hamid wrote: > Hi, Mojca, Aditya, Hans, and all the MP gurus, > > Thank you for all the help and advice. > > On Fri, 30 Jun 2006 18:17:23 -0600, Mojca Miklavec > <[EMAIL PROTECTED]> wrote: > > Wow... Ok, following is my present, still naive code. What I would like to > be able to do is > > 1) In the first figure [square], control the relation of the front and > back face of the cube by a single parameter. So if I use z for the front > face coordinates, I can use z' for the rear face and define z' as a > function of z. Then the angle of the z111--z'111 diagonal wrt the x-axis > will change, and the label for that axis will have to change as well. I've > been manually calculating inverse tangents to do this but can it be done > automatically?
angle(...). > 2. In the second figure, to in addition control the distance between the 2 > cubes by a single parameter without recalculating the dashed lines mapping > the two. See code below. > I only started yesterday but i can see that MetaPost is going to turn me > into a junkie if I'm not careful :-) > > Any other suggestions for improving/streamlining this is greatly > appreciated: I think it will make a nice example case for beginners/on the > wiki when done! I do not have an ingeneous solution like Mojca. I will do this in a brute force way like you, but using loops for repetitive tasks and allowing metapost to do all the calculations for me. \setuppapersize[letter][letter] \setupcolors[state=start] \setuppagenumbering[state=stop] \def\AXIS#1#2#3{(#1) Axis #2: {\bf #3}} \forceMPTEXcheck{LABELL} \forceMPTEXcheck{LABELR} \forceMPTEXcheck{LABELM} \startMPenvironment \ssxx\setupinterlinespace \stopMPenvironment \startMPinclusions vardef [EMAIL PROTECTED](expr s, p)= [EMAIL PROTECTED](textext("% \framed[width=1.5cm,align=left,frame=off,autowidth=force,strut=on]{" & s & "}"),p) enddef ; vardef [EMAIL PROTECTED](expr s, p)= [EMAIL PROTECTED](textext("% \framed[width=1.5cm,align=right,frame=off,autowidth=force,strut=on]{" & s & "}"),p) enddef ; vardef [EMAIL PROTECTED](expr s, p)= [EMAIL PROTECTED](textext("% \framed[align=middle,frame=off,autowidth=force,strut=on]{" & s & "}"),p) enddef ; picture my_dash ; my_dash := dashpattern(on 1mm off 1mm) ; % my_dash is more verbose than p. \stopMPinclusions \startstaticMPfigure{square} numeric u ; u := 1.4cm; % Always declare the type of a variable. Helps in debugging. path p; p := unitsquare scaled 5u ; % Identify the corners z[1] = llcorner p ; z[2] = ulcorner p ; z[3] = urcorner p ; z[4] = lrcorner p ; % Identify the corners of the shifted rectangle for i = 5 upto 8: z[i] = z[i-4] shifted (2u, 1.25u) ; endfor ; % Find the intersection points z[9] = whatever[z[5],z[6]] = whatever[z[2],z[3]] ; z[10] = whatever[z[5],z[8]] = whatever[z[3],z[4]] ; % Axis location % No need to calculate these explicitly, you can as well use % label(p, 0.5[...]) ; z[11] = 0.5[z[1],z[4]] ; z[12] = 0.5[z[1],z[2]] ; z[13] = 0.5[z[1],z[5]] ; % z[13] = (1u,0.15u) ; Not sure which point you had calculated. drawoptions(withcolor .625red withpen pencircle scaled 0.4pt) ; draw p ; draw (z[6] -- z[7]) ; draw (z[7] -- z[8]) ; draw (z[6] -- z[9]) ; draw (z[10] -- z[8]) ; % draw (z[2] -- z[6]) ; % draw (z[3] -- z[7]) ; % draw (z[4] -- z[8]) ; for i = 2 upto 4 : draw(z[i] -- z[i+4]) ; endfor ; drawoptions(withcolor .625red dashed my_dash withpen pencircle scaled 0.4pt) ; % draw (z[1] -- z[5]) ; % draw (z[9] -- z[5]) ; % draw (z[5] -- z[10]) ; for i = 1,9,10 : draw(z[5] -- z[i] ) ; endfor ; drawoptions(withcolor black) ; LABELL.llft("(0,0,0,0) Light Condensed Small Sans~Serif", z[1]) ; LABELL.llft("(0,1,0,0) Light Extended Small Sans~Serif", z[2]) ; LABELR.lrt ("(1,1,0,0) Bold Extended Small Sans~Serif", z[3]) ; LABELR.lrt ("(1,0,0,0) Bold Condensed Small Sans~Serif", z[4]) ; LABELR.urt("(0,0,1,0) Light Condensed Large Sans~Serif", z[5]) ; LABELR.urt("(0,1,1,0) Light Extended Large Sans~Serif", z[6]) ; LABELR.urt("(1,1,1,0) Bold Extended Large Sans~Serif", z[7]) ; LABELR.urt("(1,0,1,0) Bold Condensed Large Sans~Serif", z[8]) ; LABELM.bot ("\AXIS{x}{1}{Weight}", z[11]); picture p; p := textext("\framed[align=middle,frame=off,autowidth=force,strut=on]% {\AXIS{y}{2}{Width}}"); p := p rotatedaround (z[12], 90) ; label.lft(p,z[12]); p := textext("\AXIS{z}{3}{Optical Size}"); p := p rotatedaround (z[13], angle(z[5]-z[1])) ; % inv tan(1.5/2) % Let metapost calculate it for you % Ugly kludge label(p,z[13]+(0,2labeloffset)); % currentpicture := currentpicture scaled 0.9 ; % Why? Either change u, or use scaled= option in \usestaticMPfigure \stopstaticMPfigure \startstaticMPfigure{2squares} numeric u ; u := 0.7cm; path p; p := unitsquare scaled 5u ; % Identify the corners z[1] = llcorner p ; z[2] = ulcorner p ; z[3] = urcorner p ; z[4] = lrcorner p ; % Identify the corners of the shifted rectangle for i = 5 upto 8: z[i] = z[i-4] shifted (2u, 1.25u) ; endfor ; for i = 11 upto 18: z[i] = z[i-10] shifted (10u,-2.5u) ; endfor ; z[19] = (3.125u,3.125u) ; z[20] = (13.125u,0.625u) ; z[21] = (5u,-1.25u) ; drawoptions(withcolor .625red withpen pencircle scaled 0.4pt) ; for i = 0,10: draw (z[i+1] -- z[i+2] -- z[i+3] -- z[i+4] -- cycle) ; draw (z[i+5] -- z[i+6] -- z[i+7] -- z[i+8] -- cycle) ; draw (z[i+1] -- z[i+5]) ; draw (z[i+2] -- z[i+6]) ; draw (z[i+3] -- z[i+7]) ; draw (z[i+4] -- z[i+8]) ; endfor ; % Remove repetitions % draw (z[11] -- z[12] -- z[13] -- z[14] -- cycle) ; % draw (z[15] -- z[16] -- z[17] -- z[18] -- cycle) ; % draw (z[11] -- z[15]) ; % draw (z[12] -- z[16]) ; % draw (z[13] -- z[17]) ; % draw (z[14] -- z[18]) ; % map square to square drawoptions(withcolor .625red dashed my_dash withpen pencircle scaled 0.4pt) ; for i = 1 upto 8 : draw z[i] -- z[i+10] ; endfor ; % draw (z[1] -- z[11]) ; % draw (z[2] -- z[12]) ; % draw (z[3] -- z[13]) ; % draw (z[4] -- z[14]) ; % draw (z[5] -- z[15]) ; % draw (z[6] -- z[16]) ; % draw (z[7] -- z[17]) ; % draw (z[8] -- z[18]) ; % labels drawoptions(withcolor black) ; label (textext("Sans Serif"),z[19]) ; label (textext("Serif"),z[20]) ; picture p; p := textext("\AXIS{a}{4}{Serif}"); % p := p rotatedaround (z[21], -14.036) ; p := p rotatedaround (z[21], angle(z[11]-z[1])) ; label.bot(p,z[21]); % currentpicture := currentpicture scaled 0.9 ; \stopstaticMPfigure \starttext \midaligned{\usestaticMPfigure[square]} \blank[2*big] \midaligned{\usestaticMPfigure[2squares]} \stoptext Aditya _______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context