2

I want to obtain the coordinate of the incenter of a triangle. I would like to have a macro

\incenter{name}{a}{b}{c}

which sets a coordinate name at the incenter of the triangle whose vertices have coordinates a,b,c.

I wanted to use this calculation using Cartesian coordinates with the let command but this do not work with coordinates.

3
  • 1
    please provide a MWE. Commented Feb 17, 2016 at 12:50
  • 1
    See 7.5 from tkz-euclide package.
    – Sigur
    Commented Feb 17, 2016 at 12:52
  • For the equilateral case only, you can use shapes.geometric, I think. But tkz-euclide is probably the answer. (Unfortunately for me, much of the documentation is only available in French.)
    – cfr
    Commented Feb 17, 2016 at 13:07

2 Answers 2

7

This is taken more-or-less directly from the tkz-euclide documentation (texdoc -s euclide):

\documentclass[border=2mm]{standalone}

\usepackage{tkz-euclide}
\usetkzobj{all}

\newcommand{\incenter}[4]{%
    \begin{tikzpicture}
        \tkzInit[xmax=5,ymax=4]
        \tkzClip
        \tkzDefPoint(0,0){#2} %% Put the coordinates here
        \tkzDefPoint(5,1){#3} %% for the desired
        \tkzDefPoint(1,4){#4} %% triangle.
        \tkzDrawPolygon[color=red](#2,#3,#4)
        \tkzInCenter(#2,#3,#4)
        \tkzGetPoint{G}
        \tkzDrawPoint(G)
        \node[below] at (G) {#1};
    \end{tikzpicture}
}

\begin{document}

\incenter{name}{a}{b}{c}

\end{document}

example of tkz-euclide incenter

One more thing. If you want to specify an arbitrary triangle with \incenter, then you could try this:

\documentclass[border=2mm]{standalone}

\usepackage{tkz-euclide}
\usetkzobj{all}

\newcommand{\incenter}[2]{%
    \begin{tikzpicture}
        \foreach \x/\y [count=\i from 1] in {#2}{\tkzDefPoint(\x,\y){n-\i}}
        \tkzInit[xmax=5,ymax=4]
        \tkzClip
        \tkzDrawPolygon[color=red](n-1,n-2,n-3)
        \tkzInCenter(n-1,n-2,n-3)
        \tkzGetPoint{G}
        \tkzDrawPoint(G)
        \node[below] at (G) {#1};
    \end{tikzpicture}
}

\begin{document}

\incenter{Incenter!}{0/0.5,5/3,1/4}% {label}{x_1/y_1,x_2/y_2,x_3/y_3}

\end{document}

enter image description here

1
  • After learning about tkz-euclid I can say now that I basically wanted \tkzInCenter(a,b,c) \tkzGetPoint(name). Apparently my question was not clearly stated.
    – bitt.j
    Commented Feb 17, 2016 at 13:26
6

If you don't mind working in points:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{math}
\begin{document}
\begin{tikzpicture}[x=1pt, y=1pt]
\draw [thick] (0, 0) coordinate (A) -- (20, 40) coordinate (B)
   -- (40, 10) coordinate (C) -- cycle;
\tikzmath{%
  coordinate \p, \I;
  \p1 = (A); \p2 = (B); \p3 = (C);
  \a = veclen(\px3-\px2, \py3-\py2);
  \b = veclen(\px1-\px3, \py1-\py3);
  \c = veclen(\px2-\px1, \py2-\py1);
  % Get the inradius
  \s = (\a + \b + \c) / 2;
  \K = sqrt(\s) * sqrt(\s - \a) * sqrt(\s - \b) * sqrt(\s - \c);
  \r = \K / \s;
  % Normalize the lengths a bit
  \m = max(\a, \b, \c);
  \a = \a / \m; \b = \b / \m; \c = \c / \m;
  % Get the incenter
  \ix = (\a*\px1 + \b*\px2 + \c*\px3) / (\a + \b + \c);
  \iy = (\a*\py1 + \b*\py2 + \c*\py3) / (\a + \b + \c);
  \I = (\ix, \iy);
}
\fill (\I) circle [radius=1];
\draw [red] (\I) circle [radius=\r];
\end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    To work not in points, you could change the last line of the \tikzmath command to \I = (\ix pt, \iy pt);. Commented Jan 20, 2018 at 17:11
  • Complementing what @AndrewStacey has written, if one changes that line to \I = (\ix pt, \iy pt); and also change the line after it to \draw [red] (\I) circle [radius=\r pt];, then one can delete [x=1pt, y=1pt] and work on the default unit of a larger document.
    – Fabricio
    Commented Apr 7, 2020 at 17:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .