3

The junction between the end of the arrow and the segment is not precise:why and how to correct this ?

    \documentclass[border=5mm]{standalone}
    \usepackage{luatex85}
    \usepackage{luamplib}
    \usepackage{unicode-math}
    \setmainfont{TeX Gyre Pagella}
    \setmathfont{TeX Gyre Pagella Math}
    \begin{document}
    \mplibtextextlabel{enable}
    \begin{mplibcode}
    beginfig(1);
    numeric u;
    u = 1cm;

    interim linejoin := mitered;
    interim ahangle := 30;

   z0 = (0,0);
   z1 = (4u,0);
   z2 = z1 rotatedaround(z0,50);
   z3 = whatever[z0,z1];
   (z2-z3) dotprod (z1-z0) = 0;
            
  color pink, forest, royal;
  pink = (3/4, 1/3, 1/3);
  forest = (1/3, 2/3, 1/4);
  royal = (1/3, 1/3, 2/3);

  path sq;
  sq = unitsquare scaled 6;

 fill sq shifted z3 withcolor 1/2[forest, white];

 draw fullcircle scaled 1cm shifted z1 withcolor red;

 drawoptions(withpen pencircle scaled 1.25pt);
            
 draw sq shifted z3 withcolor forest;

 draw z0--z1--z2--cycle withcolor pink;

 drawoptions();

 draw z2 -- z3 dashed evenly withcolor pink;
            
 drawoptions(withpen pencircle scaled 1.25pt withcolor 3/4[white,blue]);
 drawarrow z0 -- z1;
 drawarrow z0 -- z2;
 drawoptions();

 label.bot("$H$", z3);
 label.bot("$A$",z0);
 label.bot("$B$",z1);
 label.top("$C$",z2);

 endfig;
 \end{mplibcode}
 \end{document}

enter image description here

1
  • Try it without linejoin=mitered...
    – Thruston
    May 17, 2021 at 21:12

1 Answer 1

3

The issue here is a bad interaction between the line width you have chosen, the narrow setting of ahangle and the linejoin mode.

If you look at plain.mp you will see that the arrow head to be filled is defined like this:

(q rotated .5ahangle & reverse q rotated -.5ahangle -- cycle)  shifted e

where q is the last ahlength of the arrow path and e is the point at the end of it.

The & means the arrow head shape turns a sharp corner at the tip (as you generally want). This works well with the default pen width (1/2 bp) and the default linejoin.

But when you set linejoin := mitered, MP delegates the drawing of the angle to PostScript, so you are at the mercy of the way that PostScript deals with sharp angles. And in this case, it means that the arrow sticks out some way beyond e.

And the effect is particularly bad with the thick pen you have chosen.

To make your arrows stop at the right places, the simple approach is just not change the default value of linejoin. This is what your diagram looks like with line 14 commented out:

enter image description here

But now your little green box looks a bit strange... So if you must use linejoin := mitered then you need the extra internal variable that gives you some control over it. By default MP sets miterlimit = 10; but if you reduce this below a critical value then the PostScript stick-out effect can be avoided.

Here is your diagram with

interim linejoin := mitered;
miterlimit := 3;

enter image description here

So now the arrows are in the right places and the green box looks ok, but the blue corner at A is rounded, so that you can see the pink triangle sticking out underneath.

I think the lesson from all this is that Metapost arrows and other sharp corners work best with the default line join settings, and with a limited range of line widths. If you use anything much bigger than pencircle scaled 1 you are likely to have to take extra care with all corners.

Here is a reference chart from my Drawing with Metapost notes (section 14). The lines here are draw with pencircle scaled 2 to exaggerate the effects. In general the defects are less obvious with pencircle scaled 1/2.

enter image description here

1
  • Very informative as usual ; I will take your comments into account . Thank you so much.
    – Fabrice
    May 18, 2021 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.