# [NTG-context] Metapost label alignment etc.

Idris Samawi Hamid ishamid at colostate.edu
Sat Jul 1 04:14:27 CEST 2006

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
<mojca.miklavec.lists at gmail.com> wrote:

>> I did find the
>>
>> u := 1cm;
>> z  = (2u,6u) ;
>>
>> method; is there another way, a macro perhaps?
>
> What about this one?
>
> 	save u; numeric u; u = 1cm;
>
> 	% point[x][y][z]  x,y,z are coordinates (each one can be 1 or 2)
> 	% put one point to a fix location
> 	z111 = origin;
>
> 	% same y coordinate
> 	y111 = y211;  y121 = y221;  y112 = y212;  y122 = y222;
>
> 	% same x coordinate
> 	x111 = x121;  x112 = x122;  x211 = x221;  x212 = x222;
>
> 	% face
> 	x211 - x111 = y121 - y111 = 5u;
>
> 	% define the diagonals (you could define other relations instead)
> 	z112 - z111 = z122 - z121 = z212 - z211 = z222 - z221 = (2u,1u);
>
> But you could also define them using something like
>
> for i=0 upto 1:
>   for j=0 upto 1:
>     for k=0 upto 1:
>       z[i][j][k] = (i+k*something,j+k*somethingelse) scaled u;
>     endfor;
>   endfor;
> endfor;
>
> I guess that you could draw the dashed lines by only clipping the path.
>
> Metapost is a magician. You almost never need to manually calculate
> anything!

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?

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.

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!

Best
Idris

=============meta-test.tex===========
% output=pdf interface=en
\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 LABELL@\#(expr s, p)= label@\#(textext("%
\framed[width=1.5cm,align=left,frame=off,autowidth=force,strut=on]{" & s &
"}"),p)
enddef ;

vardef LABELR@\#(expr s, p)= label@\#(textext("%
\framed[width=1.5cm,align=right,frame=off,autowidth=force,strut=on]{" & s
& "}"),p)
enddef ;

vardef LABELM@\#(expr s, p)= label@\#(textext("%
\framed[align=middle,frame=off,autowidth=force,strut=on]{" & s & "}"),p)
enddef ;

picture p ; p := dashpattern(on 1mm off 1mm) ;

\stopMPinclusions

\startstaticMPfigure{square}

u := 1.4cm;

z  = origin ;
z  = (0,5u) ;
z  = (5u,5u) ;
z  = (5u,0) ;
z  = (2u,1.25u) ;
z  = (2u,6.25u) ;
z  = (7u,6.25u) ;
z  = (7u,1.25u) ;
z  = (2u,5u) ;
z = (5u,1.25u) ;
z = (2.5u,0) ;
z = (-.17u,1.2u) ;
z = (1u,0.15u) ;

drawoptions(withcolor .625red withpen pencircle scaled 0.4pt) ;

draw (z  -- z -- z -- z -- cycle) ;
draw (z  -- z) ;
draw (z  -- z) ;
draw (z  -- z) ;
draw (z -- z) ;
draw (z  -- z) ;
draw (z  -- z) ;
draw (z  -- z) ;

drawoptions(withcolor .625red dashed p withpen pencircle scaled 0.4pt) ;

draw (z -- z)  ;
draw (z -- z)  ;
draw (z -- z) ;

drawoptions(withcolor black) ;

LABELL.llft("(0,0,0,0) Light Condensed Small Sans~Serif", z) ;
LABELL.llft("(0,1,0,0) Light Extended  Small Sans~Serif", z) ;
LABELR.lrt ("(1,1,0,0) Bold  Extended  Small Sans~Serif", z) ;
LABELR.lrt ("(1,0,0,0) Bold  Condensed Small Sans~Serif", z) ;

LABELR.urt("(0,0,1,0)  Light Condensed Large Sans~Serif", z) ;
LABELR.urt("(0,1,1,0)  Light Extended  Large Sans~Serif", z) ;
LABELR.urt("(1,1,1,0)  Bold  Extended  Large Sans~Serif", z) ;
LABELR.urt("(1,0,1,0)  Bold  Condensed Large Sans~Serif", z) ;

LABELM.bot ("\AXIS{x}{1}{Weight}", z);

picture p; p :=
textext("\framed[align=middle,frame=off,autowidth=force,strut=on]%
{\AXIS{y}{2}{Width}}");
p := p rotatedaround (z, 90) ;

label.top(p,z);

picture p; p := textext("\AXIS{z}{3}{Optical Size}");
p := p rotatedaround (z, 32.005) ; % inv tan(1.5/2)

label.top(p,z);

currentpicture := currentpicture scaled 0.9 ;

\stopstaticMPfigure

\startstaticMPfigure{2squares}

u := 0.7cm;

z  = origin ;
z  = (0,5u) ;
z  = (5u,5u) ;
z  = (5u,0) ;
z  = (2u,1.25u) ;
z  = (2u,6.25u) ;
z  = (7u,6.25u) ;
z  = (7u,1.25u) ;

z  = (10u,-2.5u) ;
z  = (10u,2.5u) ;
z  = (15u,2.5u) ;
z  = (15u,-2.5u) ;
z  = (12u,-1.25u) ;
z  = (12u,3.75u) ;
z  = (17u,3.75u) ;
z  = (17u,-1.25u) ;

z  = (3.125u,3.125u) ;
z  = (13.125u,0.625u) ;
z  = (5u,-1.25u) ;

drawoptions(withcolor .625red withpen pencircle scaled 0.4pt) ;

draw (z  -- z -- z -- z -- cycle) ;
draw (z  -- z -- z -- z -- cycle) ;
draw (z -- z) ;
draw (z -- z) ;
draw (z -- z) ;
draw (z -- z) ;

draw (z  -- z -- z -- z -- cycle) ;
draw (z  -- z -- z -- z -- cycle) ;
draw (z -- z) ;
draw (z -- z) ;
draw (z -- z) ;
draw (z -- z) ;

% map square to square

drawoptions(withcolor .625red dashed p withpen pencircle scaled 0.4pt) ;

draw (z -- z) ;
draw (z -- z) ;
draw (z -- z) ;
draw (z -- z) ;
draw (z -- z) ;
draw (z -- z) ;
draw (z -- z) ;
draw (z -- z) ;

% labels

drawoptions(withcolor black) ;

label (textext("Sans Serif"),z) ;
label (textext("Serif"),z) ;

picture p; p := textext("\AXIS{a}{4}{Serif}");
p := p rotatedaround (z, -14.036) ;

label.bot(p,z);

currentpicture := currentpicture scaled 0.9 ;

\stopstaticMPfigure

\starttext

\midaligned{\usestaticMPfigure[square]}

\blank[2*big]

\midaligned{\usestaticMPfigure[2squares]}

\stoptext
=====================================

--
Professor Idris Samawi Hamid
Department of Philosophy
Colorado State University
Fort Collins, CO 80523

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


More information about the ntg-context mailing list