3

My drawing with MetaPost looks like:

enter image description here

I need to solve the following in the graph:

  • Making the ends of the hyperbolas parallel with the two dashed lines
  • Labelling the two focus points F like F_1 and F_2.
  • Making all the labels smaller

Any help would be greatly appreciated.

MWE

\documentclass{article} 
\usepackage[T1]{fontenc} 
\usepackage[estonian]{babel} 
\usepackage{mathpazo} 
\begin{document}

etex;
def genereeri(expr w, h, base) = 
begingroup 
write "\documentclass{article}" to base&".tex"; 
write "\usepackage{geometry}" to base&".tex"; 
write "\usepackage[pdftex]{graphicx}" to base&".tex"; 
write "\DeclareGraphicsRule{*}{mps}{*}{}" to base&".tex"; 
write "\geometry{papersize={"& decimal(ceiling(w)) & "bp," &% 
decimal(ceiling(h)) & "bp}}" to base&".tex"; 
write "\geometry{margin={0bp,0bp}}" to base&".tex"; 
write "\geometry{noheadfoot,nomarginpar}" to base&".tex"; 
write "\begin{document}" to base&".tex"; 
write "\thispagestyle{empty}" to base&".tex"; 
write "\noindent\includegraphics{" & jobname & "." &% 
decimal(charcode) & "}" to base&".tex"; 
write "\end{document}" to base&".tex"; 
write EOF to base&".tex"; 
endgroup 
enddef;

beginfig(1);

drawarrow (-2cm,0)--(2cm,0);
drawarrow (0,-1.5cm)--(0,1.5cm);

label.bot("x", (1.5cm, 0));
label.lft("y", (0,1.5cm));

draw (-1.3cm,-1.3cm) -- (1.3cm,1.3cm) dashed evenly;
draw (-1.3cm,1.3cm) -- (1.3cm,-1.3cm) dashed evenly;

draw(1cm,-0.82cm) .. (0.4cm, 0) .. (1cm,0.82cm) withpen pencircle scaled 1.5pt;
draw(-1cm,-0.82cm) .. (-0.4cm, 0) .. (-1cm,0.82cm) withpen pencircle scaled 1.5pt;


draw(-0.1cm, -0.7cm) -- (0.75cm,0.9cm);

label.top("R", (0.275cm,0));
draw (0.275cm, 0) withpen pencircle scaled 2bp;

draw(1.4cm, -0.4cm) -- (0.25cm,0.7cm);

label.bot("F", (0.7cm,0cm));

label.rt("S", (0, -0.6cm));

label.bot("F", (-0.7cm,0cm));

label.bot("M", (0.8cm, 0.7cm));

label.bot("Joon.9.2.", (0, -1.5cm));
endfig;
end

numeric w,h; 
w := xpart urcorner bbox currentpicture -% 
xpart llcorner bbox currentpicture; 
h := ypart urcorner bbox currentpicture -% 
ypart llcorner bbox currentpicture; 
string base; 
base:=jobname&"_"&decimal(charcode); 
genereeri(w, h, base);

\end{document}
  • Could you please help us by showing us your current coding for this figure? – Franck Pastor Dec 18 '17 at 15:01
  • Right, forgot to add that, edited original post – Fred Dec 18 '17 at 15:18
  • Er… where is the attempted code for the hyperbola? – Franck Pastor Dec 18 '17 at 17:06
  • I'm very amateur to using metapost, so I just tried to use draw(1cm,-0.82cm) .. (0.4cm, 0) .. (1cm,0.82cm) withpen pencircle scaled 1.5pt; draw(-1cm,-0.82cm) .. (-0.4cm, 0) .. (-1cm,0.82cm) withpen pencircle scaled 1.5pt; to make the hyperbola arcs, but it didn't work and I didn't find any help from the Internet – Fred Dec 18 '17 at 17:19
  • You need to specify the function for the hyperbola. I don't understand all the stuff with base, but input latexmp may be helpful if this isn't happening automatically. You can use LaTeX commands for the font selection. At least, I do. You can specify a path and then draw it later - not sure, but this is probably easier for drawing a more complex curve. – cfr Dec 19 '17 at 2:33
5

Here is an attempt to draw the hyperbola x^2 - y^2 = 1 with its focal points and asymptotes. The MetaPost code has been inserted in a LuaLaTeX program for convenience. It calls the Metafun format, mainly because it provides the hyperbolic functions, which I use to create the parametric curve giving the hyperbola.

To make you familiar with MetaPost and the way it should be used, I suggest a wonderful tutorial from André Heck, Learning MetaPost by doing.

\documentclass[border=3mm]{standalone}
\usepackage{luatex85, luamplib}
\usepackage{luamplib}
    \mplibsetformat{metafun}
    \mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
% Macro creating a parametric path
vardef parafcn(expr tmin, tmax, tstep)(text f_t)(text g_t) =
    save t; t := tmin;
    (f_t, g_t) forever: hide(t := t + tstep) exitunless t <= tmax; 
        .. (f_t, g_t) 
    endfor
    if t - tstep < tmax: hide(t := tmax) .. (f_t, g_t) fi
enddef;
% Parameters
u = cm; xmax = ymax = - xmin = -ymin = 4; 
tmax = -tmin = 2.2; tstep = .1;
beginfig(1);
    % Axes
    drawarrow (xmin*u, 0) -- (xmax*u, 0);   
    drawarrow (0, ymin*u) -- (0, ymax*u);
    % Focus points
    pair F[]; F1 = (u*sqrt 2, 0) = -F2;
    for i = 1,2:
        drawdot F[i] withpen pencircle scaled 3bp; 
        label.bot("$F_{" & decimal i & "}$", F[i]);
    endfor;
    % Asymptotes
    drawoptions(dashed evenly);
    draw ((xmin, ymin) -- (xmax, ymax)) scaled u;
    draw ((xmin, ymax) -- (xmax, ymin)) scaled u;
    drawoptions(withpen pencircle scaled bp withcolor red);
    % (Clipped) Hyperbola
    path hyperb;
    hyperb = parafcn(tmin, tmax, tstep)(cosh t)(sinh t) scaled u;
    draw hyperb; draw hyperb reflectedabout (origin, (0, 1));
    clip currentpicture to 
        ((xmin, ymin) -- (xmax, ymin) -- (xmax, ymax) -- (xmin, ymax) -- cycle) 
            scaled u;
    % labels
    drawoptions();
    label.bot("$x$", (xmax*u, 0)); label.lft("$y$", (0, ymax*u));
endfig;
\end{mplibcode}
\end{document}

enter image description here

  • 1
    You can extend the -xmin = xmax = 4 type syntax to pairs, so here you could have put F1 = -F2 = (u*sqrt 2,0). – Thruston Dec 20 '17 at 16:58
  • @Thruston Quite right. Done! – Franck Pastor Dec 20 '17 at 17:10

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.