尝试使用 tikz 库获取三角形中心的坐标intersections
。这些线足够长,实际上可以相交,并且它们只相交一次。在图中,我预计黑点位于蓝线和红线的交点处。我做错了什么?感谢帮助
\documentclass[border=3pt,tikz]{standalone}
\usetikzlibrary{intersections,through,shapes,shapes.geometric}
\usetikzlibrary{calc}
% side lengths of triangle
\newcommand{\AB}{5cm}
\newcommand{\AC}{12cm}
\newcommand{\BC}{13cm}
\begin{document}
\begin{tikzpicture}[scale=0.6,thick]
% draw points B and C horizontally (arbitrary choice)
\coordinate (B) at (0, 0);
\coordinate (C) at (\BC, 0);
% get coordinates of A based on position of B and C
\begin{pgfinterruptboundingbox}% prevent spacing from spilling out
% draw circle with center B and radius AB
\node (r1) at (B) [circle through=($ (B) + (0:\AB) $)] {};
% draw circle with center C and radius AC
\node (r2) at (C) [circle through=($ (C) + (0:\AC) $)] {};
\end{pgfinterruptboundingbox}
% A lies at the intersection of the two circles
\coordinate (A) at (intersection 2 of r1 and r2);
% draw triangle ABC
\draw (B) node[below left] {$B$}
-- (C) node[below right] {$C$}
-- (A) node[above] {$A$}
-- cycle;
% path of angle bisector at A
\coordinate (A1) at ($(A)!10cm!(B)$);
\coordinate (A2) at ($(A)!10cm!(C)$);
\coordinate (A3) at ($(A1)!0.5!(A2)$); % midpoint
\draw[name path=A4,blue] (A) -- (A3);
% path of angle bisector at C
\coordinate (C1) at ($(C)!15cm!(A)$);
\coordinate (C2) at ($(C)!15cm!(B)$);
\coordinate (C3) at ($(C1)!0.5!(C2)$); % midpoint
\draw[name path=C4,red] (C) -- (C3);
% center of the inscribed circle
\coordinate[name intersections={of={C4} and {A4}, by={O}}];
\draw[fill] (O) circle (2pt);
\end{tikzpicture}
\end{document}
答案1
问题似乎出在coordinate
与 结合使用的命令上name-intersections
。您可以改用或path
,例如。draw
fill
\path[name intersections={of=C4 and A4, by={O}}];
\documentclass[border=3pt,tikz]{standalone}
\usetikzlibrary{intersections,through,shapes,shapes.geometric}
\usetikzlibrary{calc}
% side lengths of triangle
\newcommand{\AB}{5cm}
\newcommand{\AC}{12cm}
\newcommand{\BC}{13cm}
\begin{document}
\begin{tikzpicture}[scale=0.6,thick]
% draw points B and C horizontally (arbitrary choice)
\coordinate (B) at (0, 0);
\coordinate (C) at (\BC, 0);
% get coordinates of A based on position of B and C
\begin{pgfinterruptboundingbox}% prevent spacing from spilling out
% draw circle with center B and radius AB
\node (r1) at (B) [circle through=($ (B) + (0:\AB) $)] {};
% draw circle with center C and radius AC
\node (r2) at (C) [circle through=($ (C) + (0:\AC) $)] {};
\end{pgfinterruptboundingbox}
% A lies at the intersection of the two circles
\coordinate (A) at (intersection 2 of r1 and r2);
% draw triangle ABC
\draw (B) node[below left] {$B$}
-- (C) node[below right] {$C$}
-- (A) node[above] {$A$}
-- cycle;
% path of angle bisector at A
\coordinate (A1) at ($(A)!10cm!(B)$);
\coordinate (A2) at ($(A)!10cm!(C)$);
\coordinate (A3) at ($(A1)!0.5!(A2)$); % midpoint
\draw[name path=A4,blue] (A) -- (A3);
% path of angle bisector at C
\coordinate (C1) at ($(C)!15cm!(A)$);
\coordinate (C2) at ($(C)!15cm!(B)$);
\coordinate (C3) at ($(C1)!0.5!(C2)$); % midpoint
\draw[name path=C4,red] (C) -- (C3);
% center of the inscribed circle
\path[name intersections={of=C4 and A4, by={O}}];
\draw[fill] (O) circle (2pt);
% alternative
% \fill[name intersections={of=C4 and A4, by={O}}] (O) circle (2pt);
\end{tikzpicture}
\end{document}