关于在 MetaPost 中绘图的帮助

关于在 MetaPost 中绘图的帮助

我使用 MetaPost 绘制的图如下:

在此处输入图片描述

我需要解决图中的以下问题:

  • 使双曲线的端点与两条虚线平行
  • 标记两个焦点F喜欢F_1F_2
  • 缩小所有标签

任何帮助将不胜感激。

平均能量损失

\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}

答案1

这是绘制双曲线x^2 - y^2 = 1及其焦点和渐近线的尝试。为方便起见,MetaPost 代码已插入 LuaLaTeX 程序中。它调用 Metafun 格式,主要是因为它提供了双曲函数,我使用它来创建给出双曲线的参数曲线。

为了让您熟悉 MetaPost 及其使用方法,我推荐 André Heck 的精彩教程,通过实践学习 MetaPost

\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}

在此处输入图片描述

相关内容