2

Say we have a given isosceles triangle (for example sides of lengths 8,12,12) and a given segment length a, smaller than the triangle's base (e.g. a=6).

How can I draw such a rectangle inscribed into the triangle that has two sides of length a (without manually calculating the other side's length) using TikZ/PGFPlots?

/EDIT: As promised, my try. The values are different for the sake of simplicity.

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

Awful solution, isn't it? :)

  • 8
    I think you should at least show a minimal working example (aka MWE) and some effort. – Dr. Manuel Kuehner Mar 9 '15 at 19:54
  • I'll do, tomorrow – marmistrz Mar 9 '15 at 21:05
  • 4
    This isn't homework, is it? – cfr Mar 9 '15 at 22:47
  • 1
    @marmistrz Let us see your try! – Svend Tveskæg Mar 10 '15 at 21:02
  • I will, surely, but I'm short on free time lately. When I find a while, sure. – marmistrz Mar 11 '15 at 5:15
5

TikZ solution

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

enter image description here

2

With MetaPost, without comments.

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

enter image description here

1

A PSTricks solution:

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

output

All you have to do is choose the values of \lengthLeg, \lengthBase, and \widthRectangle; the drawing will then be adjusted accordingly.

0

An homothetic solution :

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.