TikZ 中取得錯誤的交點

TikZ 中取得錯誤的交點

目的是繪製三角形的所有三個角平分線。這裡ABC是一個三角形。 (a1,a2)、(b1,b2)和(c1,c2)對分別表示頂點A、B和C處的圓弧的起點和終點。我想做的是取線 A -- ($(a1​​)!0.5!(a2)$) 和對應的邊 BC 並得到它們的交點(例如 k1)。然後我將使用頂點和交點 k1 來繪製角平分線。對剩餘的兩個頂點重複此操作。但我的問題是,當我嘗試取得線的交點時,我得到了點 c1。

這是我的程式碼:

\documentclass[11pt,a4paper]{article}

\usepackage[margin=0.75in,marginparsep=0pt]{geometry}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

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


\begin{document}
\begin{tikzpicture}
% vertices of the triangle
\coordinate[label=below:{$A(x_1,y_1)$}] (A) at (0,0);
\coordinate[label=below:{$B(x_2,y_2)$}] (B) at (4.5cm, 0);
\coordinate[label=above:{$C(x_3,y_3)$}] (C) at (6cm, 5cm);

% drawing triangle
\draw[name path=trg] (A) -- (B) -- (C) -- cycle;

% circle at each vertex A, B and C to get intersection
% points with triangle
\path[name path=circa] (A) circle (6mm);
\path[name path=circb] (B) circle (6mm);
\path[name path=circc] (C) circle (6mm);

% labeling intersections of circles and each vertex angle
\path [name intersections={of=trg and circa, by={a1,a2}}]; % at vertex A
\path [name intersections={of=trg and circb, by={b1,b2}}]; % at vertex B
\path [name intersections={of=trg and circc, by={c1,c2}}]; % at vertex C


% drawing arc at each vertex
\draw[bend right] (a1) to (a2);
\draw[bend right] (b2) to (b1);
\draw[bend right] (c2) to (c1);

\path[name path=AB] (A) -- (B);
\path[name path=BC] (B) -- (C);
\path[name path=CA] (C) -- (A);

% determining intersection of angle bisector and 
% corresponding side of the triangles
\path[name path=abs1] (A) -- ($(a1)!0.5!(a2)$);
\path[name intersections={of=abs1 and BC, by={k1}}];
\fill[red] (k1) circle [radius=2pt];

\path[name path=abs2] (B) -- ($(b1)!0.5!(b2)$);
\path[name intersections={of=abs2 and CA, by={k2}}];
\fill[red] (k2) circle [radius=2pt];

\path[name path=abs3] (C) -- ($(c1)!0.5!(c2)$);
\path[name intersections={of=abs3 and AB, by={k3}}];
\fill[red] (k3) circle [radius=2pt];

% drawing angle bisectors
% the problem is that k1, k2, and k3 are at the same place
\draw [red] (A) -- (k1); 
\draw [red] (B) -- (k2);
\draw [red] (C) -- (k3);
\end{tikzpicture}


\end{document}

答案1

線段abs1與線段BC沒有交集...您可以abs1透過以下方式放大您的線段:

\path[overlay,name path=abs1] (A) -- ($(A)!20!($(a1)!0.5!(a2)$)$);

我任意選擇該值20並新增該overlay選項,以免干擾邊界框的計算。

在此輸入影像描述

\documentclass[]{standalone}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

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


\begin{document}
\begin{tikzpicture}
% vertices of the triangle
\coordinate[label=below:{$A(x_1,y_1)$}] (A) at (0,0);
\coordinate[label=below:{$B(x_2,y_2)$}] (B) at (4.5cm, 0);
\coordinate[label=above:{$C(x_3,y_3)$}] (C) at (6cm, 5cm);

% drawing triangle
\draw[name path=trg] (A) -- (B) -- (C) -- cycle;

% circle at each vertex A, B and C to get intersection
% points with triangle
\path[name path=circa] (A) circle (6mm);
\path[name path=circb] (B) circle (6mm);
\path[name path=circc] (C) circle (6mm);

% labeling intersections of circles and each vertex angle
\path [name intersections={of=trg and circa, by={a1,a2}}]; % at vertex A
\path [name intersections={of=trg and circb, by={b1,b2}}]; % at vertex B
\path [name intersections={of=trg and circc, by={c1,c2}}]; % at vertex C


% drawing arc at each vertex
\draw[bend right] (a1) to (a2);
\draw[bend right] (b2) to (b1);
\draw[bend right] (c2) to (c1);

\path[name path=AB] (A) -- (B);
\path[name path=BC] (B) -- (C);
\path[name path=CA] (C) -- (A);

% determining intersection of angle bisector and 
% corresponding side of the triangles
\path[overlay,name path=abs1] (A) -- ($(A)!20!($(a1)!0.5!(a2)$)$);
\path[name intersections={of=abs1 and BC, by={k1}}];
\fill[red] (k1) circle [radius=2pt];

\path[overlay,name path=abs2] (B) -- ($(B)!20!($(b1)!0.5!(b2)$)$);
\path[name intersections={of=abs2 and CA, by={k2}}];
\fill[red] (k2) circle [radius=2pt];

\path[overlay,name path=abs3] (C) -- ($(C)!15!($(c1)!0.5!(c2)$)$);
\path[name intersections={of=abs3 and AB, by={k3}}];
\fill[red] (k3) circle [radius=2pt];

% drawing angle bisectors
% the problem is that k1, k2, and k3 are at the same place
\draw [red] (A) -- (k1); 
\draw [red] (B) -- (k2);
\draw [red] (C) -- (k3);
\end{tikzpicture}


\end{document}

相關內容