展开一个片段(Metapost)

展开一个片段(Metapost)

如何延伸线段 [II']、[JJ'] 和 [AA'](如图所示)?

在此处输入图片描述

 \documentclass[border=5mm]{standalone}
 \usepackage{luatex85}
 \usepackage{luamplib}
 \mplibtextextlabel{enable}
 \begin{document}
 \begin{mplibcode}
  beginfig(0);
  numeric u;
  u = 10mm;

  pickup pencircle scaled 1pt;

  angle_radius := 8pt;

  def mark_rt_angle (expr a, b, c, d) =
     fill ((1,0)--(1,1)--(0,1)--origin--cycle)
     zscaled (angle_radius*unitvector(a-b))
     shifted b withcolor d;
     draw ((1,0)--(1,1)--(0,1))
     zscaled (angle_radius*unitvector(a-b)) shifted b;
  enddef;

  % macro drawing a circular arc (Franck Pastor)

  vardef arc(expr theta_min, theta_max) =
    save theta, mystep ; 
    mystep = 1; theta = theta_min ;
    dir theta_min 
    for theta = theta_min+mystep step mystep until theta_max:
    .. dir theta endfor 
    enddef; 

   z0=(4u,0);
   z1=z0 rotated 90;
   z2=z1 rotated 120;
   z3=z2 rotated 120;
   z4=0.5[z2,z3];
   z5=z3 rotatedaround (z2,180);
   z6=z3 rotatedaround (z2,90);
   z7=z3 rotatedaround (z2,-90);

   path triangle; triangle = z1--z2--z3--cycle;
   theta_min := 0;
   theta_max := 60;
   pair center; center = origin;
   r := 0.5u; 
   myeps := 0.25u ; path p, a, b;
   a = (center -- center + dir theta_min) scaled r shifted z2;
   b = (center -- center + dir theta_max) scaled r shifted z2;
   p = arc(theta_min, theta_max) scaled (r) shifted z2;

  fill b -- a -- p -- cycle withcolor green;
  fill triangle withcmykcolor(0.00,0.03,0.44,0.2);
  fill b -- a -- p -- cycle withcmykcolor (1,0.00,1,0.07);
  mark_rt_angle (z3, z4, z1, green);
  draw z1--z4 withcolor blue;
  draw fullcircle scaled 2abs(z3-z2) shifted z2;
  draw z6 -- z7;
  draw z3 -- z5;
  draw triangle withpen pencircle scaled 1.5bp withcmykcolor(0,0.5,0.69,0);
  draw z1 withpen pencircle scaled 4bp withcolor red;
  draw z4 withpen pencircle scaled 4bp withcolor red;

  label.bot(btex $A'$ etex,z4);
  label.llft(btex $O$ etex,z2);
  label.rt(btex $I$ etex,z3);
  label.top(btex $A$ etex,z1);
  label.lft(btex $I'$ etex,z5);
  label.top(btex $J$ etex, z6);
  label.bot(btex $J'$ etex, z7);

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

答案1

您可以将格式设置为 MetaFun,这样您就可以访问shortened路径操作。当使用负长度时,shortenend路径将延伸而不是修剪。

我擅自缩短并清理了您的代码。

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\mplibsetformat{metafun}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
beginfig(0);
    % Definitions
    numeric u; u = 10mm;

    pair O ; O := origin ;
    pair A ; A := (2u, sqrt(3)*2u) ;
    pair Aprime ; Aprime := (xpart A, ypart O) ;

    % Determine radius
    numeric r ; r := arclength (O -- A) ;
    pair I ; I := (r, ypart O) ;

    % Axes
    draw (-I -- O -- I) shortened -.5u ;
    draw (-I -- O -- I) shortened -.5u rotated 90 ;

    % Enclosing circle
    draw fullcircle scaled (2*r) ;

    % Triangle (only fill)
    path triangle ; triangle := O -- A -- I -- cycle ;
    fill triangle withcmykcolor(0.00,0.03,0.44,0.2) ;

    % Angle
    path arc ; arc := O -- anglebetween(O -- I, O -- A, " ") -- cycle ;
    fill arc withcolor green ;
    draw arc withcmykcolor (1,0.00,1,0.07) ;

    % Right angle
    draw image (
        fill unitsquare scaled .5u withcolor green ;
        draw unitsquare scaled .5u withcmykcolor (1,0.00,1,0.07) ;
    ) shifted Aprime ;
    draw (A -- Aprime) shortened -1cm withcolor blue ;

    % Draw triangle
    draw triangle withpen pencircle scaled 1.5bp withcmykcolor(0,0.5,0.69,0) ;

    % Mark A and A' with dots
    picture dot ; dot := image (
        fill fullcircle scaled 4pt withcolor red ;
        draw fullcircle scaled 4pt withcolor white ;
    ) ;
    draw dot shifted A ;
    draw dot shifted Aprime ;

    % Labels
    label.llft("$O$", O) ;
    label.lrt("$I$", I) ;
    label.llft("$I'$", -I) ;
    label.ulft("$J$", I rotated 90) ;
    label.urt("$A$", A) ;
    label.lrt("$A'$", Aprime) ;
endfig;
end
\end{mplibcode}
\end{document}

在此处输入图片描述

答案2

只是为了好玩,用 Ti 替代Z. 至少从表面上看,这似乎比 MetaPost 代码更短更简单。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{angles}
\begin{document}
\begin{tikzpicture}[declare function={R=3;}]
 \draw[thick] (0,0) coordinate (O) circle[radius=R] 
  (-R,0) coordinate[label=below left:$I'$] (I') 
  (R,0)  coordinate[label=below right:$I$] (I)  
  (0,R) coordinate[label=above left:$J$] (J)
  (0,-R) coordinate[label=below left:$J'$] (J');
 \draw[shorten >=-1em,shorten <=-1em,thick]  (I) -- (I');
 \draw[shorten >=-1em,shorten <=-1em,thick]  (J) -- (J');
 \draw[red,fill=red!30] (0,0) -- (60:R) coordinate (A)  -- (I) -- cycle
  coordinate[midway] (A');
 \pic[draw=green!70!black, fill=green, angle radius=6mm]{angle=I--O--A};
 \draw[thick,blue] (A|-0,R*1cm+1em) -- (A|-0,-R*1cm-1em); 
 \path pic[draw=green!70!black, fill=green, angle radius=4mm]{right angle=I--A'--A}
  (A) node[circle,inner sep=1pt,fill=red,label=above right:$A$]{}
  (A') node[circle,inner sep=1pt,fill=red,label=below right:$A'$]{};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

只关注“扩展”线段的具体问题......

在您的特定图表中,如果将圆心放在 上origin,那么您可以使用一个简单的scale操作来制作一条更长的线,因此如果您将主圆定义为

path C; C = fullcircle scaled 200;

然后为了让你的延长线通过II'你可以尝试:

draw (point 0 of C -- point 4 of C) scaled 1.1;

但这依赖于C以 为中心origin。因此,为了更通用,你必须写一些繁琐的东西,例如

draw (point 0 of C -- point 4 of C) shifted - center C scaled 1.1 shifted center C;

如果优先规则设计得不那么好,情况可能会更糟。

另一方面,如果您已经有两个点z0z1并且想要通过这两个点延伸一个线段,那么您可以使用如下中介语法:

draw (-0.1)[z0, z1] -- 1.1[z0, z1];

z0这从 10%“之前”的点到 10%“之后”的点画了一条直线z1。如果负面中介的想法让你不快,那么你可以交换点的顺序:

draw 1.1[z1, z0] -- 1.1[z0, z1];

最后,由于其他人已经尝试重新绘制您的代码,这里是另一个用于比较的努力(使用 进行编译lualatex)。请注意,您只需更改圆的大小和 的值即可更改它p。其他所有内容都应相对于这些进行计算。

\documentclass[border=5mm]{standalone}
\usepackage{luatex85}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    path C, T, arc, sq, xx, yy;
    C = fullcircle scaled 140;

    numeric p;
    p = 4/3;
    T = origin -- point 0 of C -- point p of C -- cycle;
    arc = origin -- subpath (0, p) of fullcircle scaled 20 -- cycle;
    sq = unitsquare scaled 6 shifted (xpart point p of C, 0);

    xx = (point 4 of C -- point 0 of C) scaled 1.1;
    yy = (point 6 of C -- point 2 of C) scaled 1.1;

    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);

    fill T withcolor 1/2[pink, white];

    fill sq  withcolor 1/2[forest, white]; draw sq  withcolor forest;
    fill arc withcolor 1/2[forest, white]; draw arc withcolor forest;

    draw T withcolor pink;

    draw xx;
    draw yy;
    draw C withpen pencircle scaled 3/4;

    draw yy shifted point 0 of sq withcolor royal;

    label.llft("$O$", origin);
    label.lrt("$I$", point 0 of C);
    label.ulft("$J$", point 2 of C);
    label.llft("$I'$", point 4 of C);

    label.urt("$A$", point p of C);
    label.lrt("$A'$", (xpart point p of C, 0));

    fill fullcircle scaled dotlabeldiam shifted point p of C withcolor 2/3 red;
    draw fullcircle scaled dotlabeldiam shifted point p of C withcolor white;

    fill fullcircle scaled dotlabeldiam shifted (xpart point p of C, 0) withcolor 2/3 red;
    draw fullcircle scaled dotlabeldiam shifted (xpart point p of C, 0) withcolor white;

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

在此处输入图片描述

相关内容