TikZ - 将矩形内接于三角形

TikZ - 将矩形内接于三角形

假设我们有一个给定的等腰三角形(例如边长为 8,12,12)和一个给定的线段长度a,小于三角形的底边(例如a=6)。

如何使用 TikZ/PGFPlots绘制一个内接于具有两条边长度的三角形的矩形a(无需手动计算另一条边的长度)?

/EDIT:正如承诺的那样,我尝试了。为了简单起见,值有所不同。

\begin{tikzpicture}
    \draw (3,0) -- (0,8) -- (-3,0) -- cycle;
    \draw (2,0) -- (2,y) -- (-2,y); % where y is calculated manually, e.g. from the similar triangles properties
\end{tikzpicture}

糟糕的解决方案,不是吗?:)

答案1

TikZ 解决方案

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{geometry}
\usetikzlibrary{positioning,calc,intersections}


\begin{document}

\begin{tikzpicture}

\draw (-4,0)coordinate(a)--(4,0)coordinate(b);
\path[name path=C1] (8,0) arc (0:90:12);
\path[name path=C2] (-8,0) arc (180:90:12);
\path[name intersections={of=C1 and C2,by=s}]  ;
\draw[name path=T0] (b)--(s) --(a);
\path[name path=T1] (-3,0) -- ++(0,10);
\path[name path=T2] (3,0) -- ++(0,10);
\path[name intersections={of=T0 and T1,by={b1}}]  ;

\path[name intersections={of=T0 and T2,by=b2}] ;

\draw (a-|b1) --(b1) --(b2) --(a-|b2);

\end{tikzpicture}

\end{document} 

在此处输入图片描述

答案2

使用 MetaPost,无需评论。

\documentclass[border = 2bp]{standalone}
\usepackage{luamplib}
    \mplibsetformat{metafun}
    \mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
beginfig(1);
    u = cm; a = 6; b = 8; c = 12;

    z1 + z2 = origin; z2 - z1 = u*b*right;
    z3 = u*(c +-+ .5b)*up;
    draw z1 -- z2 -- z3 -- cycle;

    z4 - z1 = z2 - z5; z5 - z4 = u*a*right;
    z6 = whatever[z5, z5 + up] = whatever[z2, z3];
    z7 = whatever[z4, z4 + up] = whatever[z1, z3];
    draw z4 -- z5 -- z6 -- z7 -- cycle;

    label.top("$" & decimal a & "$", .5[z6, z7]);
    draw image(drawdblarrow z1 -- z2; label.bot("$" & decimal b & "$", origin)) 
        yshifted -2.5labeloffset;
    draw thelabel.top("$" & decimal c & "$", .5[z1, z3]) 
        rotatedaround (.5[z1, z3], angle(z3 - z1));
    draw thelabel.top("$" & decimal c & "$", .5[z2, z3]) 
        rotatedaround (.5[z2, z3], angle(z2 - z3));
endfig;
\end{mplibcode}
\end{document}

在此处输入图片描述

答案3

PSTricks 解决方案:

\documentclass{article}

\usepackage{pst-node}
\usepackage{xfp}

\newcommand*\const{\fpeval{sqrt((2*\lengthLeg)^2-\lengthBase^2)}}
\newcommand*\Middle{\fpeval{\lengthBase/2}}
\newcommand*\height{\fpeval{\const/2}}
\newcommand*\pointXa{\fpeval{(\lengthBase-\widthRectangle)/2}}
\newcommand*\pointXb{\fpeval{(\lengthBase+\widthRectangle)/2}}
%\newcommand*\pointXb{\fpeval{\pointXa+\widthRectangle}}
\newcommand*\pointY{\fpeval{\height*(\lengthBase-\widthRectangle)/\lengthBase}}

%%% Parameters
% Assumption: 2*\lengthLeg > \lengthBase > \widthRectangle
\def\lengthLeg{12}
\def\lengthBase{8}
\def\widthRectangle{6}

\psset{unit = \fpeval{min(1,8/\lengthLeg)}, dimen = m}

\begin{document}

\begin{pspicture}(0,-0.6)(\lengthBase,\height)
  \pspolygon(0,0)(\Middle,\height)(\lengthBase,0)
  \psframe(\pointXa,0)(\pointXb,\pointY)
  \uput[270](\Middle,0){$\lengthBase$}
  \uput[90](\Middle,\pointY){$\widthRectangle$}
 \psset{linestyle = none, offset = 9pt}
  \pcline(0,0)(\Middle,\height)
  \ncput{$\lengthLeg$}
%  \pcline(\Middle,\height)(\lengthBase,0)
%  \ncput{$\lengthLeg$}
\end{pspicture}

\end{document}

输出

\lengthLeg您所要做的就是选择、\lengthBase和的值\widthRectangle;然后绘图将进行相应的调整。

答案4

一个位似解:

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}

\def\Base{8}
\def\Rect{6}

\coordinate (A) at (-\Base/2,0) ;
\coordinate (B) at (\Base/2,0) ;

\begin{scope}
\clip (0,0) rectangle (0,0) ;
\draw[name path=C1] (\Base,0) arc (0:90:12);
\draw[name path=C2] (-\Base,0) arc (180:90:12);
\path[name intersections={of=C1 and C2,by=C}]  ;
\end{scope}

\coordinate (A') at ($(C)!\Rect/\Base!(A)$) ;
\coordinate (B') at ($(C)!\Rect/\Base!(B)$) ;

\draw (A)--(B)--(C)--cycle ;
\draw (A-|A')--(A')--(B')--(B-|B') ;

\end{tikzpicture}
\end{document} 

相关内容