在线段上创建刻度标记

在线段上创建刻度标记

这个想法是重现图形,使得点 U 的横坐标为 -5/7,点 P 的根为 13。我对 Metapost 的练习不足以完成这个图形。

在此处输入图片描述

  \documentclass[border=5mm]{standalone}
  \usepackage{luatex85}
  \usepackage{luamplib}
  \begin{document}
  \mplibtextextlabel{enable}
  \begin{mplibcode}
   beginfig(1);
        u  = 1.5cm;
        z0 = (0,0);
        z1 = (-2u,0);
        z2 = (4u,0);
        z3 = (u,0);
        z4 = (sqrt(13)*u,0);
        z5 = ((-5/7)*u,0);
        z6 = (0,-3*u);
        z7 = (2u,-3u);
        z8 = (2u,0);

        path q;
        q = unitsquare scaled 5;

        picture X;
        X = image(
        drawoptions(withpen pencircle scaled 1.25 withcolor 1/4[blue, white]);
        draw (left--right) scaled 2;
        draw (down--up) scaled 2;
        drawoptions();
        );

        draw X shifted z0;
        draw X shifted z3;
        draw X shifted z4;
        draw X shifted z5;

        fill q rotated 180 shifted z8 withcolor 1/3[green, white];
        draw q rotated 180 shifted z8 ;

        fill q rotated -90 shifted z0 withcolor 1/3[green, white];
        draw q rotated -90 shifted z0 ;

        fill q rotated 90  shifted z7 withcolor 1/3[green, white];
        draw q rotated 90 shifted z7 ;

        fill q  shifted z6 withcolor 1/3[green, white];
        draw q  shifted z6 ;

        draw z0 -- z7 withcolor 1/2[red, white];

        draw z1 -- z2;
        path rectangle;
        rectangle = z0 -- z6 -- z7 -- z8 -- cycle;
        draw rectangle;

        label.lrt("$U$",z5);
        label.top("$O$",z0 + (0,3));
        label.top("$I$",z3 + (0,3));
        label.top("$P$",z4 + (0,3));
        label.lft("3",0.5[z0, z6]) withcolor 1/2[red, black];
        label.bot("2",0.5[z6, z7]) withcolor 1/2[red, black];
        label.bot("$-1$", (-u,0));

        path r;
        r = fullcircle scaled 7.211102551u;

        draw subpath (6.5, 8) of r;
        draw (-1)[z0, point 2.35 of rectangle] -- 1.8[z0, point 2.35 of rectangle]  withcolor 1/2[blue, white];
        
        pair A;
        A = fullcircle scaled 3.5cm intersectionpoint ((-0.8)[z0, point 2.35 of rectangle] -- 1.8[z0, point 2.35 of rectangle]);
       
        
        draw  (-2)[A, z5] -- 5[A, z5] withcolor red;
        draw  ((-2)[A, z5] -- 5[A, z5]) shifted ((-2/7)*cm,0) withcolor red;

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

在此处输入图片描述

答案1

像这样?(已更正)

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
u  = 1.5cm;
z0 = (0,0);
z1 = (-2u,0);
z2 = (4u,0);
z3 = (u,0);
z4 = (sqrt(13)*u,0);
z5 = ((-5/7)*u,0);
z6 = (0,-3*u);
z7 = (2u,-3u);
z8 = (2u,0);

path q;
q = unitsquare scaled 5;

picture X;
X = image(
drawoptions(withpen pencircle scaled 1.25 withcolor 1/4[blue, white]);
draw (left--right) scaled 2;
draw (down--up) scaled 2;
drawoptions();
);

draw X shifted z0;
draw X shifted z3;
draw X shifted z4;
draw X shifted z5;

fill q rotated 180 shifted z8 withcolor 1/3[green, white];
draw q rotated 180 shifted z8 ;

fill q rotated -90 shifted z0 withcolor 1/3[green, white];
draw q rotated -90 shifted z0 ;

fill q rotated 90  shifted z7 withcolor 1/3[green, white];
draw q rotated 90 shifted z7 ;

fill q  shifted z6 withcolor 1/3[green, white];
draw q  shifted z6 ;

draw z0 -- z7 withcolor 1/2[red, white];

draw z1 -- z2;
path rectangle;
rectangle = z0 -- z6 -- z7 -- z8 -- cycle;
draw rectangle;

label.lrt("$U$",z5);
label.top("$O$",z0 + (0,3));
label.top("$I$",z3 + (0,3));
label.top("$P$",z4 + (0,3));
label.lft("$3$",0.5[z0, z6]) withcolor 1/2[red, black];
label.bot("$2$",0.5[z6, z7]) withcolor 1/2[red, black];
label.llft("$-1$", (-u,0)) withcolor 1/2[red, black];

path r;
r = fullcircle scaled 7.211102551u;

draw subpath (6.5, 8) of r;
z9 = (-1)[z0, point 2.35 of rectangle];
z10 = 1.8[z0, point 2.35 of rectangle];
draw z9 -- z10  withcolor 1/2[blue, white];

pair A;
A = fullcircle scaled 3.5cm intersectionpoint ((-0.8)[z0, point 2.35 of rectangle] -- 1.8[z0, point 2.35 of rectangle]);

z11 = (-1)[A, z5];
z12 = 5[A, z5];

z13 = z11 shifted (2/7 u * left);  % <- 2/7 u not 2/7 cm!
z14 = z12 shifted (2/7 u * left);

draw z11 -- z12 withcolor red;
draw z13 -- z14 withcolor red;

z15 = whatever[z13, z14] = whatever[z9, z10];
path mark;  mark = (down -- up) scaled 2 rotated angle (z10-z9);
for i=0 upto 7:
    draw mark shifted (i/7)[z15, z0] withcolor 1/2[blue, white];
endfor

% alternative approach for equal ticks
picture ticks; ticks = image(
    draw (down--up) scaled 3/2 rotated -13 shifted 1/2 left withcolor red;
    draw (down--up) scaled 3/2 rotated -13 shifted 1/2 right withcolor red;
);
for i=1/2 upto 6+1/2:
    draw ticks rotated angle (z10-z9) shifted (i/7)[z15, z0];
endfor

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

相关内容