Draw two perpendiculars (Metapost)
I call the rectangle vertices A, B, C, D (a
, b
, c
and d
in the MetaPost code). I also define points M' and N' so that the segments you are interested in are [MM'] and [NN'] (see the figure below). I propose two other techniques to draw these segments:
- Tell MetaPost that
mprime
lies on the (c,d) line and that (m,mprime) is parallel to (a,d):mprime = whatever[c,d]; mprime - m = whatever*(d-a);
- Tell MetaPost that
nprime
lies on the (b,c) line and that (n,nprime) is perpendicular to (b,c):nprime = whatever[b,c]; (nprime - n) dotprod (c-b) = 0;
I leave out the two double arrows from your figure, as they are irrelevant to the question. Here is a complete example showing the two ideas given above in action, and using a quartercircle
of radius AM:
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
defaultfont := "texgyrepagella-regular*default" ;
defaultscale := 0.8 ;
pair a, b, c, d, m, n, mprime, nprime;
path rect, qcircle;
rect = unitsquare xscaled 4cm yscaled 2cm;
a = point 0 of rect;
b = point 1 of rect;
c = point 2 of rect;
d = point 3 of rect;
m = point 0.3 of rect;
qcircle = quartercircle scaled (2*abs(m-a));
n = rect intersectionpoint reverse(qcircle);
mprime = whatever[c,d];
nprime = whatever[b,c];
mprime - m = whatever*(d-a); % declare parallelism
(nprime - n) dotprod (c-b) = 0; % declare perpendicularity
draw rect;
draw qcircle;
draw m -- mprime;
draw n -- nprime;
label.bot("$A$", a);
label.bot("$B$", b);
label.top("$C$", c);
label.top("$D$", d);
label.bot("$M$", m);
label.lft("$N$", n);
label.top("$M'$", mprime);
label.rt ("$N'$", nprime);
endfig;
\end{mplibcode}
\end{document}
For interests sake, I tried to come up with a couple of additional options. Neither is particularly convenient, but if you're just learning metapost
(like I am), then maybe something useful is in here.
Option 1:
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(0);
defaultfont := "texgyrepagella-regular*default" ;
defaultscale := 0.8 ;
path p,q,r,s;
picture pic;
p = unitsquare xscaled 4cm yscaled 2cm;
q = quartercircle scaled 2.4cm;
z0 = p intersectionpoint q;
% draw a big cross and chop off the portions outside of the rectangle.
r:=(x0,0)--(x0,infinity) cutafter reverse p;
s:=(0,x0)--(infinity,x0) cutafter p;
draw p;
draw q;
draw s;
draw r;
label.bot("M",z0);
label.lft("N",(0,x0));
label.llft("O",origin);
label.bot("x",.5[origin,z0]);
label.bot("B", point 1 of p);
endfig;
\end{mplibcode}
\end{document}
Option 2:
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(0);
defaultfont := "texgyrepagella-regular*default" ;
defaultscale := 0.8 ;
path p,q,r;
picture pic;
p = unitsquare xscaled 4cm yscaled 2cm;
q = quartercircle scaled 2.4cm;
z0 = p intersectionpoint q;
r = (x0,-infinity)--(x0,infinity);
% store big cross
pic := image(
draw r;
draw r rotated 90;
);
% and chop off portion outside of the rectangles bounding box.
% this was unexpected, the bounding box provides extra space, so didn't clip exactly.
begingroup;
interim bboxmargin := 0;
clip pic to bbox p;
endgroup;
draw pic;
draw p;
draw q;
label.bot("M",z0);
label.lft("N",(0,x0));
label.llft("O",origin);
label.bot("x",.5[origin,z0]);
label.bot("B", point 1 of p);
endfig;
\end{mplibcode}
\end{document}