[Tex/LaTex] Instructing TikZ to calculate the radius of a circle inscribed in a triangle

tikz-pgf

I have the code for a triangle, and I have located the center of the circle that can be inscribed in it. I want to draw the inscribed circle without using the formula for the radius of the inscribed circle in a triangle. How do I get TikZ to calculate this radius and to draw the circle?

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{tikzpicture}

\path (0,1) coordinate (A) (3.5,1.5) coordinate (B) (-1.5,-0.75) coordinate (C);
\draw (A) -- (B) -- (C) -- cycle;

%The angle bisector at A is drawn.
\coordinate (a_path_for_angle_bisector_at_A) at ($(A)!2cm!(B)$);
\coordinate (another_path_for_angle_bisector_at_A) at ($(A)!2cm!(C)$);
\coordinate (midpoint_on_line_segment_to_locate_angle_bisector_at_A) at ($(a_path_for_angle_bisector_at_A)!0.5!(another_path_for_angle_bisector_at_A)$);
\path[name path=a_path_to_locate_center_of_circle] (A) -- ($(A)!1cm!(midpoint_on_line_segment_to_locate_angle_bisector_at_A)$);

%The angle bisector at C is drawn.
\coordinate (a_path_for_angle_bisector_at_C) at ($(C)!2cm!(A)$);
\coordinate (another_path_for_angle_bisector_at_C) at ($(C)!2cm!(B)$);
\coordinate (midpoint_on_line_segment_to_locate_angle_bisector_at_C) at ($(a_path_for_angle_bisector_at_C)!0.5!(another_path_for_angle_bisector_at_C)$);
\path[name path=another_path_to_locate_center_of_circle] (C) -- ($(C)!3cm!(midpoint_on_line_segment_to_locate_angle_bisector_at_C)$);

%The center of the circle inscribed in the triangle is located.
\coordinate[name intersections={of=a_path_to_locate_center_of_circle and another_path_to_locate_center_of_circle, by={O}}];
\draw[fill] (O) circle (1.5pt);


\end{tikzpicture}

\end{document}

Best Answer

You can do it using

\draw 
  let 
  \p1=( $ ( $ (A)!(O)!(B) $ )-(O) $ )
  in
  (O) circle ({veclen(\x1,\y1)});

(the radius is the length of the segment from O to the projection of O over one of the sides).

The complete code:

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}

\path (0,1) coordinate (A) (3.5,1.5) coordinate (B) (-1.5,-0.75) coordinate (C);
\draw (A) -- (B) -- (C) -- cycle;

%The angle bisector at A is drawn.
\coordinate (a_path_for_angle_bisector_at_A) at ($(A)!2cm!(B)$);
\coordinate (another_path_for_angle_bisector_at_A) at ($(A)!2cm!(C)$);
\coordinate (midpoint_on_line_segment_to_locate_angle_bisector_at_A) at ($(a_path_for_angle_bisector_at_A)!0.5!(another_path_for_angle_bisector_at_A)$);
\path[name path=a_path_to_locate_center_of_circle] (A) -- ($(A)!1cm!(midpoint_on_line_segment_to_locate_angle_bisector_at_A)$);

%The angle bisector at C is drawn.
\coordinate (a_path_for_angle_bisector_at_C) at ($(C)!2cm!(A)$);
\coordinate (another_path_for_angle_bisector_at_C) at ($(C)!2cm!(B)$);
\coordinate (midpoint_on_line_segment_to_locate_angle_bisector_at_C) at ($(a_path_for_angle_bisector_at_C)!0.5!(another_path_for_angle_bisector_at_C)$);
\path[name path=another_path_to_locate_center_of_circle] (C) -- ($(C)!3cm!(midpoint_on_line_segment_to_locate_angle_bisector_at_C)$);

%The center of the circle inscribed in the triangle is located.
\coordinate[name intersections={of=a_path_to_locate_center_of_circle and another_path_to_locate_center_of_circle, by={O}}];
\draw[fill] (O) circle (1.5pt);

\draw 
  let 
  \p1=( $ ( $ (A)!(O)!(B) $ )-(O) $ )
  in
  (O) circle ({veclen(\x1,\y1)});

\end{tikzpicture}

\end{document}

enter image description here

Related Question