我正在尝试连接两个通过极坐标相对于另一个点定义的点。
考虑下图。目标是用黑线连接 B 和 C。但是,我的代码没有达到正确的结果。
\begin{tikzpicture}[>=latex]
\coordinate (fov) at (0, 2);
\fill[red] (fov) circle (2pt) node[anchor=east] {A};
\draw[red] (fov) -- ++(295:2cm);
\draw[red] (fov) -- ++(335:2cm);
\fill[red] (fov)++(295:2cm) circle (2pt) node[anchor=east] {B};
\fill[red] (fov)++(335:2cm) circle (2pt) node[anchor=south] {C};
\draw (fov)++(295:2cm) -- (fov)++(335:2cm);
\end{tikzpicture}
我究竟做错了什么?
注意:最终目标是填充三角形 ABC。
答案1
以下示例将单个路径操作合并为更紧凑的形式。所需的坐标在第一次使用时定义。线条位于圆圈后面(红色圆圈上方的黑线对我来说看起来太奇怪了)。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[>=latex]
\draw[red]
(0, 2) coordinate (fov)
-- +(295:2cm) coordinate (B)
(fov) -- +(335:2cm) coordinate (C);
\draw (B) -- (C);
\fill[red, radius=2pt]
(fov) circle node[anchor=east] {A}
(B) circle node[anchor=east] {B}
(C) circle node[anchor=south] {C};
\end{tikzpicture}
\end{document}
答案2
您可以将坐标放在路径的末尾,然后连接它们:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[>=latex]
\coordinate (fov) at (0, 2);
\fill[red] (fov) circle (2pt) node[anchor=east] {A};
\draw[red] (fov) -- ++(295:2cm);
\draw[red] (fov) -- ++(335:2cm);
\fill[red] (fov)++(295:2cm) coordinate (b) circle (2pt) node[anchor=east] {B};
\fill[red] (fov)++(335:2cm) coordinate (c) circle (2pt) node[anchor=south] {C};
\draw (b) -- (c);
\end{tikzpicture}
\end{document}
也许在库的帮助下重写代码calc
会给你带来更好的结果(黑色段不会覆盖红色填充点):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[>=latex]
\coordinate (fov) at (0, 2);
\fill[red] (fov) circle (2pt) node[anchor=east] {A};
\draw[red] (fov) -- ++(295:2cm);
\draw[red] (fov) -- ++(335:2cm);
\coordinate (b) at ( $ (fov) + (295:2cm) $ );
\coordinate (c) at ( $ (fov) +(335:2cm) $ );
\draw (b) -- (c);
\fill[red] (b) circle (2pt) node[anchor=east] {B};
\fill[red] (c) circle (2pt) node[anchor=south] {C};
\end{tikzpicture}
\end{document}
答案3
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[>=latex]
\begin{scope}{shift={(0,2)}}
\coordinate (fov) at (0,0) ;
\coordinate (B) at (295:2cm) ;
\coordinate (C) at (335:2cm) ;
\end{scope}
\fill[blue!20] (fov)--(B)--(C)--cycle ;
\fill[red] (fov) circle (2pt) node[anchor=east] {A};
\fill[red] (B) circle (2pt) node[anchor=north] {B};
\fill[red] (C) circle (2pt) node[anchor=west] {C};
\end{tikzpicture}
\end{document}