7

I am trying to recreate the following picture in tkz-euclide. One big question I have is if there is a way to create a triangle using only the side lengths. In other words I would like to avoid using trigonometry or any other complication to draw the triangle accurately.

enter image description here

Here is my attempt:

\begin{tikzpicture}
    \tkzDefPoint (0,0){A}
    \tkzDefPoint (3.07,0){B}
    \tkzDefPoint (1.89,1.38){C}
    \tkzDrawPolygon (A,B,C)
    \tkzInCenter(A,B,C)\tkzGetPoint{G}
    \tkzDrawPoint(G)
    \tkzDrawCircle[in](A,B,C)
\end{tikzpicture}
  • 3
    The easiest way is probably to take the code you provide of what you've tried, and then to tweak that... maybe. – Werner Mar 17 '16 at 1:08
  • I have posted my attempted at the problem. I had to use the law of cosines to get the angle and then sines and cosines to get the coordinates for point B. – 1028 Mar 17 '16 at 1:33
  • 2
    Welcome to TeX.SX!! It is better to post a full minimal working example that starts with a \documentclass command, has a minimal preamble and then \begin{document}...\end{document}. Unless the problem is a compilation error, the code should compile and be as small as possible to demonstrate your problem. This makes it much easier for people to help you --- and much more likely that they will! – Andrew Mar 17 '16 at 6:36
  • All these answers are great and very interesting to see how people go about solving the same problem differently. I really liked jake's solution and Alan's was a refinement of that and completely solved the problem. – 1028 Mar 17 '16 at 23:04
8

Based on Jake's answer with some refinements

\documentclass[border=5mm]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}

    \pgfkeys{/pgf/decoration/.cd, distance/.initial = 10pt}  

    \pgfdeclaredecoration{add dim}{final}{
    \state{final}{% 
    \pgfmathsetmacro{\dist}{\pgfkeysvalueof{/pgf/decoration/distance}}
              \pgfpathmoveto{\pgfpoint{0pt}{0pt}}             
              \pgfpathlineto{\pgfpoint{0pt}{2*\dist}}   
              \pgfpathmoveto{\pgfpoint{\pgfdecoratedpathlength}{0pt}} 
              \pgfpathlineto{\pgfpoint{(\pgfdecoratedpathlength}{2*\dist}}     
              \pgfsetarrowsstart{latex}
              \pgfsetarrowsend{latex}
              \pgfpathmoveto{\pgfpoint{0pt}{\dist}}
              \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{\dist}} 
              \pgfusepath{stroke} 
              \pgfpathmoveto{\pgfpoint{0pt}{0pt}}
              \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{0pt}}
    }}

    \tikzset{
        dim/.style args={#1,#2,#3}{%
                    decoration = {add dim,distance=\ifx&#2&0pt\else#2\fi},
                    decorate,
                    postaction = {%
                       decorate,
                       decoration={%
                            raise=\ifx&#2&0pt\else#2\fi,
                            markings,
                            mark=at position .5 with {\node[inner sep=0pt,
                                                            font=\footnotesize,
                                                            fill=\ifx&#1&none\else white\fi,
                                                            #3] at (0,0) {#1};}
                       }
                    }
        },
        dim/.default={,0pt,}
    }       
\begin{tikzpicture}[scale=2]
\pgfkeys{/pgf/number format/.cd,fixed,precision=2}
% Define the first two points
\tkzDefPoint(0,0){A}
\tkzDefPoint(3.07,0){B}

% Find the intersections of the circles around A and B with the given radii
\tkzInterCC[R](A,2.37cm)(B,1.82cm)
\tkzGetPoints{C}{C'}

% Draw the interior circle
\tkzDrawCircle[in](A,B,C) \tkzGetPoint{G}
\tkzGetLength{rIn} 

% Reset the bounding box so we don't get empty space around our triangle
\pgfresetboundingbox

% Draw the triangle and the points
\tkzDrawPolygon(A,B,C)
\tkzDrawPoints(A,B,C)

% Label the sides
\tkzCalcLength[cm](A,B)\tkzGetLength{ABl}
\tkzCalcLength[cm](B,C)\tkzGetLength{BCl}
\tkzCalcLength[cm](A,C)\tkzGetLength{ACl}

% add dim
\tkzDrawSegment[dim={\pgfmathprintnumber\BCl,6pt,transform shape}](C,B)
\tkzDrawSegment[dim={\pgfmathprintnumber\ACl,6pt,transform shape}](A,C)
\tkzDrawSegment[dim={\pgfmathprintnumber\ABl,-6pt,transform shape}](A,B)

% Labels 
\tkzLabelPoints(A,B) \tkzLabelPoints[above](C)
\tkzDefShiftPoint[G](70:\rIn pt){g}  
\tkzDefShiftPoint[g](70: .5 cm){gg} \tkzDefShiftPoint[gg](0: .5 cm){ggg}  
\tkzDrawSegment[->](G,g) \tkzDrawSegment(g,gg) 
\tkzDrawLine[add=0 and 0,end={$r=?$}](gg,ggg) 
\end{tikzpicture}
\end{document}

enter image description here

  • I added add dim to tkz-base – Alain Matthes Mar 17 '16 at 19:57
10

Here's how this can be done using tkz-euclide:

\documentclass[border=5mm]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}
\begin{tikzpicture}[scale=2]

% Define the first two points
\tkzDefPoint(0,0){A}
\tkzDefPoint(3.07,0){B}

% Find the intersections of the circles around A and B with the given radii
\tkzInterCC[R](A,2.37cm)(B,1.82cm)
\tkzGetPoints{C}{C'}

% Draw the interior circle
\tkzDrawCircle[in](A,B,C)

% Reset the bounding box so we don't get empty space around our triangle
\pgfresetboundingbox

% Draw the triangle and the points
\tkzDrawPolygon(A,B,C)
\tkzDrawPoints(A,B,C)

% Label the sides
\tkzLabelSegment[below](A,B){3.07}
\tkzLabelSegment[above right](B,C){1.82}
\tkzLabelSegment[above left](A,C){2.37}

\end{tikzpicture}
\end{document}
  • This is just what I was looking for! Drawing circles at the endpoints and calculating the intersections is a really simple method! – 1028 Mar 17 '16 at 12:27
5

This only shows only the drawing of the triangle and circle, not the arrows and labels.

I draw first one side, then make two circles starting at the end points of this line. The third point is the intersection of the two circles (there are two intersections).

There are some calculations to get the radius of the incircle, the center of which is found with barycentric coordinates. I realize tkz-euclide simplifies this considerably, but there are enough examples of that in other answers, so I thought I'd add a pure TikZ suggestion for that part.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}%[rotate=-20]

% save side lenghths in macros
\pgfmathsetmacro{\sideA}{3.07}
\pgfmathsetmacro{\sideB}{1.82}
\pgfmathsetmacro{\sideC}{2.35}

% calculate semiperimeter
\pgfmathsetmacro{\semip}{(\sideA+\sideB+\sideC)/2}
% calculate radius of incircle: area (given by Heron's formula) divided by semiperimeter
\pgfmathsetmacro{\inrad}{sqrt(\semip*(\semip-\sideA)*(\semip-\sideB)*(\semip-\sideC))/\semip}

% define coordinates for points A and B
\coordinate (A) at (0,0);
\coordinate (B) at (\sideA,0);

% define circular paths centered on A and B, with radius as side AC and BC respectively
\path [name path=AC] (A) circle[radius=\sideC];
\path [name path=BC] (B) circle[radius=\sideB];

% calculate the intersection(s) of the two circles
% by default the coordinates are called intersection-N, name=C means they're called C-1 and C-2
\path [name intersections={of=AC and BC,name=C}];

% reset bounding box to avoid extra whitespace
\pgfresetboundingbox

% draw the triangle
\draw (A) -- (B) -- (C-1) -- cycle;
%\draw [help lines,dashed] (A) -- (B) -- (C-2) -- cycle;

% center of inradius given in barycentric coordinates
\coordinate (center) at (barycentric cs:A=\sideB,B=\sideC,C-1=\sideA);
\draw (center) circle[radius=\inrad];

\end{tikzpicture}
\end{document} 

enter image description here

4

Here's how I'd do it. There's some Tikz too in this code, but I suppose it's not a problem. The commented out code was not necessary so I replaced it with different code.

The lengths are automatically calculated.

Output

enter image description here

Code

\documentclass[margin=10pt]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}

\usetikzlibrary{calc, arrows.meta}

\begin{document}
\begin{tikzpicture}[rotate=-30, transform shape]
\tkzDefPoint(0,0){A}
\tkzDefPoint(3.07,0){B}
\tkzDefPoint(1.89,1.38){C}

\tkzDrawPolygon (A,B,C)

%\tkzInCenter(A,B,C)\tkzGetPoint{G}
%\tkzDrawPoint(G)
\tkzDrawCircle[in](A,B,C) \tkzGetPoint{G}
\tkzGetLength{rIn} 

\tkzCalcLength[cm](A,B)\tkzGetLength{ABl}
\tkzCalcLength[cm](B,C)\tkzGetLength{BCl}
\tkzCalcLength[cm](A,C)\tkzGetLength{ACl}

\foreach \lef/\rig/\len/\pos in {A/B/\ABl/below, B/C/\BCl/above, C/A/\ACl/above}{
    \draw[gray] ($(\lef)!0!90:(\rig)$) -- ($(\lef)!-.3!90:(\rig)$);
    \draw[gray] ($(\rig)!0!-90:(\lef)$) -- ($(\rig)!-.3!-90:(\lef)$);
    \draw[{Latex}-{Latex}] ($(\lef)!-.2!90:(\rig)$) -- ($(\rig)!-.2!-90:(\lef)$) node[\pos, midway, sloped] {\pgfmathprintnumber[fixed,precision=2]{\len}};
}

\draw[-{Latex}] (G) --++ (90:\rIn pt) coordinate (a);
\draw (G) -- ($(G)!3!(a)$) --++ (.2,0) node[right] {$r = ?$};

\end{tikzpicture}
\end{document}
  • Very cool solution using a for loop! However I believe this solution uses my calculations for the coordinate C. That coordinate was found using the law of cosines and the constraint was to avoid using that. – 1028 Mar 17 '16 at 23:09
  • @1028 you wanted to find C in another way? I don't remember that being specified in your question. – Alenanno Mar 18 '16 at 10:16
  • @Alenanno Read the second sentence of the question once more. – Torbjørn T. Mar 18 '16 at 11:28
  • @1028 Ah my bad! I think I skipped over it. I'll edit the answer asap to fit the question. – Alenanno Mar 18 '16 at 11:30
  • @Alenanno, Thank you, I am curious to see your answer! – 1028 Mar 18 '16 at 20:48
4

Perhaps you would also like a Metapost answer. This one calculates the radius of the incircle for you. Just set a, b, c to the three lengths required at the top of the figure (with a<b+c of course).

enter image description here

prologues := 3;
outputtemplate := "%j%c.eps";

vardef incircle(expr A,B,C) = 
  save i; pair i;
  i = whatever[A,A+unitvector(C-A)+unitvector(B-A)] 
    = whatever[B,B+unitvector(C-B)+unitvector(A-B)];
  fullcircle scaled 2 abs ypart((i-A) rotated -angle(C-A)) shifted i
enddef;

beginfig(1);

u = 128; % or whatever unitsize you like...

a = 3.07u;
b = 2.35u;
c = 1.82u;

z0 = origin;
z1 = right scaled a rotated -23;
z2 = fullcircle scaled 2b shifted z0
     intersectionpoint
     fullcircle scaled 2c shifted z1;

path c, t, r;
c = incircle(z0,z1,z2);
t = z0--z1--z2--cycle;     
r = center c -- point 0 of c;

answer = round(arclength r / u * 100)/100;

draw      c withcolor .768 red;
drawarrow r withcolor .768 red; label.top(decimal answer, point 1/2 of r);
draw t;

path m[]; picture n;
for i=0 upto 2:
  m[i] = subpath (i,i+1) of t shifted (unitvector(point i of t - point i+1 of t) rotated 90 scaled 12);
  drawdblarrow m[i] withcolor .6 white;
  draw (down--up) scaled 6 rotated angle direction 0 of m[i] shifted point 0 of m[i] withcolor .6 white;
  draw (down--up) scaled 6 rotated angle direction 1 of m[i] shifted point 1 of m[i] withcolor .6 white;
  n := thelabel(decimal (round(arclength m[i] / u * 100)/100), point 1/2 of m[i]);
  unfill bbox n; draw n withcolor .5 white;
endfor

endfig;
end.

Most of the effort here is to make the nice length labels for the sides of the triangle.

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.