Mediation.mp

u:=25;                    % 25 = 25bp = 25 PostScript points = 25/72 in
wi:=10;                   % width  in units u   
he:=10;                   % height in units u
hoehe:=he*u;              % height
breite:=wi*u;             % width

marklength:=2mm;          

transform t;
t:=identity scaled u;

def draw_point(expr P, colI, colP) =
  fill fullcircle scaled 1.4mm shifted P withcolor colI;
  draw fullcircle scaled 1.4mm shifted P withcolor colP;
enddef;

def mark_LineSegment(expr P, Q, ratio, c) =
  save q, E; 
  path q; pair E;
  E:=unitvector(Q-P) scaled .5marklength;
  q:=E--E rotated 180;
  draw q rotated 90 shifted ratio[P, Q] withcolor c;
enddef;

def draw_MarkedMediationPoints(expr P, Q, reverse) = 
  %
  % draw marks at mediation points
  %
  pair Z[];
  string s[];
  Z0=P transformed t;
  Z1=Q transformed t;
  if reverse:
    s0:="Q"; s1:="P";
  else:
    s0:="P"; s1:="Q";
  fi
  pickup pencircle scaled 1.5;
  draw Z0--Z1;                                    % Draw line segment 
  pickup pencircle scaled 0.5;  
  draw (-.7)[Z0, Z1]--(1.7)[Z0, Z1];              % Draw straight line    
  for i=-3 upto 8:                                % prolonging line segment
    ratio:=.2i;                                   % ratio = -.6, -.4, ..., 1.4, 1.6 
    if (i<>0) and (i<>5):
      mark_LineSegment(Z0, Z1, ratio, black);     % draw mark if i not equal to
    fi                                            % either 0 or 5 (ratios 0 and 1)
    if (i=-3) or (i=8):
      label.rt((decimal ratio)&"["&s0&","&s1&"]", 
        ratio[Z0, Z1]+(.1u,0));
    else:
      label.rt(decimal ratio, ratio[Z0, Z1]+(.1u,0));          
    fi
    if i=0:
      label.lft(s0, ratio[Z0, Z1]-(.1u,0));      
    fi
    if i=5:
      label.lft(s1, ratio[Z0, Z1]-(.1u,0));      
    fi
  endfor  
  pickup pencircle scaled 0.5; 
  draw_point(Z0, white, black);                   % Draw endpoints
  draw_point(Z1, white, black);
enddef;  

beginfig(1)
  bboxmargin:=5; 
  pair P, Q, L, versch;
  picture lab;
  P:=(1, 3);                                      % starting point of line segment
  Q:=(2, 7);                                      % end point of line segment
  L:=(0.5, 8.5);                                  % label
  versch:=(4.5, 0);
  
  % --- Draw Frame ---
  draw (0, 0)--(breite, 0)--(breite, hoehe)--(0, hoehe)--cycle;
  
  lab:=\thelabel.rt("r[P, Q]", L transformed t);  % draw left label
  unfill bbox lab; draw lab; draw bbox lab;
  
  draw_MarkedMediationPoints(P, Q, false);        % false: not reverse
                                                  % i.e. mediation order P, Q   
  P:=P shifted versch;
  Q:=Q shifted versch;  
  L:=L shifted versch+(3.1,-1);   
  
  lab:=\thelabel.rt("r[Q, P]", L transformed t);  % draw right label
  unfill bbox lab; draw lab; draw bbox lab;
    
  draw_MarkedMediationPoints(Q, P, true);         % true: reverse  
                                                  % i.e. mediation order Q, P 
					     
  label.lrt (btex 14.09.2002 etex, (0, hoehe));					     
  label.ulft(btex latex2html version 2002-1 etex rotated 90, (breite, 0));					      
endfig;

end