Tikz 中的三角图

Tikz 中的三角图

我正在尝试在 Tikz 中复制下图:

enter image description here

边界包含一个直角三角形,虚线(不在图中)连接 (0,0.5--1,0) 和 (0,1--0,5,0)。此外,它还有 2 条围绕 (1/3,1/3) 点的虚线。这些线有点像三角形,但很平滑(因此没有扭结)。

我尝试了以下操作:

\begin{tikzpicture}[scale=0.5]
    %Drawing the border
    \draw (0,0) -- (0,11) (0,0) -- (11,0);
    \draw [->] (0,11);
    \draw [->] (11,0);
    \draw (10,0) -- (0,10);
    % Drawing dashed lines
    \draw[dashed] (0,5) -- (10,0);
    \draw[dashed] (5,0) -- (0,10);
\end{tikzpicture}

但不知道如何画出这些虚线平滑三角形。请注意,这不需要遵循任何特定方程,只需粗略地画出草图即可:)。


一位敏锐的评论者指出,1/3,1/3 是在两条线的交点上!我画的图忘记了这一点。

答案1

使用smooth cycle可以绘制平滑的三角形。使用 可以使三角形变得更圆tension

\documentclass[tikz,border=3.14pt]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.5]
    %Drawing the border
    \draw (0,0) -- (0,11) (0,0) -- (11,0);
    \draw [->] (0,11);
    \draw [->] (11,0);
    \draw (10,0) -- (0,10);
    % Drawing dashed lines
    \draw[dashed] (0,5) -- (10,0);
    \draw[dashed] (5,0) -- (0,10);
    \pgfmathsetmacro{\myx}{2}
    \draw[dashed] plot[smooth cycle] coordinates {({10/3-\myx/3},{10/3+\myx})
    ({10/3+\myx},{10/3-\myx/3}) ({10/3-\myx/3},{10/3-\myx/3}) };
    \pgfmathsetmacro{\myx}{1}
    \draw[dashed] plot[smooth cycle] coordinates {({10/3-\myx/3},{10/3+\myx})
    ({10/3+\myx},{10/3-\myx/3}) ({10/3-\myx/3},{10/3-\myx/3}) };
\end{tikzpicture}
\end{document}

enter image description here

答案2

与@marmot 相同的想法,另一个代码(同时改变张力和比例因子)。

\documentclass[tikz,border=7pt]{standalone}
\begin{document}
  \begin{tikzpicture}
    %Drawing the border
    \draw (0,0) edge[-latex] (0,11) edge[-latex] (11,0) (10,0) -- (0,10);
    % Drawing dotted lines
    \draw[dotted, very thick] (0,5) -- (10,0) (5,0) -- (0,10);
    % The barycenter
    \fill[red] (10/3,10/3) coordinate (O) circle(3pt);
    % The smooth triangles
    \foreach[evaluate={\t=1-~/10}] ~ in {1,...,9}
        \draw[blue,scale around={~/10:(O)},smooth cycle,tension=\t,dashed, thick]
            plot coordinates {(0,0) (0,10) (10,0)};
  \end{tikzpicture}
\end{document}

enter image description here

答案3

我认为更实用的一个选择是使用tkz-euclide为此类图形设计的包,对于您提出的绘图,您可以使用质心(或任何其他点)并寻找朝向顶点的点,然后绘制内部三角形。

你可以得到这个:

enter image description here

或这个:

enter image description here 以下是代码:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% By J. Leon V.  coded based on the BSD, MIT, Beerware licences.
\documentclass[border=2mm]{standalone}
\usepackage{xcolor}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}
    \begin{tikzpicture}
    % Set limits.
        \tkzInit[xmax=20,xmin=-1,ymax=20, ymin=-1]
    %\tkzGrid[sub,color=blue!10!,subxstep=.5,subystep=.5] %HIDE CARTESIAN GRID
    %\tkzAxeXY %HIDEN CARTESIAN AXIS
        \tkzClip
    %Define principal points. (10X)
    \tkzDefPoint(0,0){O}
    \tkzDefPoint(11,0){X1}
    \tkzDefPoint(0,11){X2}
     %Calculate points.
    \tkzDefBarycentricPoint(O=1,X1=10) \tkzGetPoint{A}
    \tkzDefBarycentricPoint(O=1,X2=10) \tkzGetPoint{B}  
    \tkzDefMidPoint(O,A) \tkzGetPoint{C}
    \tkzDefMidPoint(O,B) \tkzGetPoint{D}
    \tkzDefBarycentricPoint(O=2,A=1) \tkzGetPoint{c} 
    \tkzDefBarycentricPoint(O=2,B=1) \tkzGetPoint{d}
    \tkzCentroid(A,B,O) \tkzGetPoint{G} 

    %DRAW AND FIND POINTS
    \foreach \y [count=\i] in {1,..., 4}{
                \tkzDefBarycentricPoint(O=1,G=\y) \tkzGetPoint{GO\i} 
                \tkzDrawPoint[fill=red,size=10pt,](GO\i) % SHOW HIDEN POINTS GO
                \tkzDefBarycentricPoint(A=1,G=\y) \tkzGetPoint{GA\i} 
                \tkzDrawPoint[fill=red,size=10pt,](GA\i) % SHOW HIDEN POINTS GA
                \tkzDefBarycentricPoint(B=1,G=\y) \tkzGetPoint{GB\i} 
                \tkzDrawPoint[fill=red,size=10pt,](GB\i) % SHOW HIDEN POINTS GB
                \draw[dashed] plot[smooth cycle] coordinates{
                    (GO\i)(GA\i)(GB\i)
                    };
                }

    \tkzDrawSegments(B,A)
    \tkzDrawSegments[dashed](B,C A,D)
    \tkzDrawVectors[thick](O,X1 O,X2)
    \tkzMarkRightAngle(X2,O,X1) % For the case of 90 degres
    \tkzDrawPoints[size=10pt,shape=cross](c,d,G)

% 
%   %Labels:
    \tkzLabelPoint[below](A){ $A$}
    \tkzLabelPoint[below](C){$A/2$}
    \tkzLabelPoint[left](B){ $B$}
    \tkzLabelPoint[left](D){$B/2$}
    \tkzLabelPoint[left](O){$O$}
    \tkzLabelPoint[below](X1){$X_1$}
    \tkzLabelPoint[left](X2){$X_2$}
    \tkzLabelPoint[below](c){$A/3$}
    \tkzLabelPoint[left](d){$B/3$}
    \tkzLabelPoint[left](G){\sf Centroid}

    \end{tikzpicture}


\end{document}

答案4

您可能还喜欢元帖子版本,展示了如何制作漂亮的平滑循环路径(红色)。这是使用luamplib编译完成的lualatex- 或者锻炼如何将其转换pdflatexgmp包(或者普通 MP)。

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\usepackage{luatex85}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    numeric u;
    u = 144;
    path xx, yy;
    xx = origin -- right scaled 1.1u;
    yy = xx rotated 90;

    z0 = (1, 1) scaled 1/3 u;

    draw (0, 1/2u) -- (u, 0) -- (0, u) -- (1/2u, 0) 
         dashed evenly scaled 1/2 
         withcolor 1/2 white;

    dotlabel.llft("$x$", z0);

    % this is how to make a nice "smooth cycle" curve
    % default tension is 1 and gives something more like a circle
    % tension infinity gives straight lines
    def :: = .. tension 3 .. enddef;
    for t=1/5, 1/3:
        draw t[z0, (0,0)] ::
             t[z0, (0,u)] ::
             t[z0, (u,0)] :: cycle 
             dashed withdots scaled 1/4
             withcolor 2/3 red;
    endfor

    drawarrow xx; label.rt ("$x_1$", point 1 of xx);
    drawarrow yy; label.top("$x_2$", point 1 of yy);

    draw (down--up) scaled 1 shifted (1/3u,0);
    draw (down--up) scaled 1 shifted (1/2u,0);
    draw (down--up) scaled 1 shifted (   u,0);
    label.bot("$\frac13$", (1/3u, 0));
    label.bot("$\frac12$", (1/2u, 0));
    label.bot("$1$", (u,0));

    draw (left--right) scaled 1 shifted (0, 1/3u);
    draw (left--right) scaled 1 shifted (0, 1/2u);
    draw (left--right) scaled 1 shifted (0,    u);
    label.lft("$\frac13$", (0, 1/3u));
    label.lft("$\frac12$", (0, 1/2u));
    label.lft("$1$", (0, u));

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

相关内容