使用 Tikz 标记交叉路口

使用 Tikz 标记交叉路口

我有以下一段代码,我想添加两点:

  1. 为红点(即线段的交点)添加标签。不幸的是,仅使用 ${...}$ 似乎不起作用。

  2. 我想从向量 a 画一个箭头到线段,表示该向量与其正交。

谢谢

\documentclass{article}
\usepackage{tikz}


\newcommand{\tikzAngleOfLine}{\tikz@AngleOfLine}
\def\tikz@AngleOfLine(#1)(#2)#3{%
\pgfmathanglebetweenpoints{%
\pgfpointanchor{#1}{center}}{%
\pgfpointanchor{#2}{center}}
\pgfmathsetmacro{#3}{\pgfmathresult}%
}

\begin{document}

\begin{tikzpicture}[scale=1.5]
\draw (-1,3) coordinate (a_1) -- (3,0) coordinate (a_2);
\draw (-1,2.7) coordinate (b_1) -- (3.5,1) coordinate (b_2);
\coordinate (a) at (intersection of a_1--a_2 and b_1--b_2);    
\fill[red] (a) circle (1pt);
\tikzAngleOfLine(a_1)(a_2){\angle};
\draw[black,->] (a_2) -- ++ (\angle+90:0.3) node[midway,above=0.1cm] {$a$};
\end{tikzpicture}
\end{document} 

答案1

  1. 您可以使用\node和它的label键。

  2. 您可以使用该angles库及其angle图片。

结果:

在此处输入图片描述

代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles}

\newcommand{\tikzAngleOfLine}{\tikz@AngleOfLine}
\def\tikz@AngleOfLine(#1)(#2)#3{%
\pgfmathanglebetweenpoints{%
\pgfpointanchor{#1}{center}}{%
\pgfpointanchor{#2}{center}}
\pgfmathsetmacro{#3}{\pgfmathresult}%
}

\begin{document}

\begin{tikzpicture}[scale=1.5]
\draw (-1,3) coordinate (a_1) -- (3,0) coordinate (a_2);
\draw (-1,2.7) coordinate (b_1) -- (3.5,1) coordinate (b_2);
\coordinate (a) at (intersection of a_1--a_2 and b_1--b_2);    
\fill[red] (a) circle (1pt);
\node[label=below:$r$] at (a) {};
\tikzAngleOfLine(a_1)(a_2){\angle};
\draw[black,->] (a_2) -- ++ (\angle+90:0.3)   
  node[midway,above=0.1cm] {$a$};
\coordinate (aux) at  ([shift={(\angle+90:20pt)}]a_2); 
\draw[<->,>=latex,red] pic[draw=red,angle radius=8pt]{angle = aux--a_2--a};
\end{tikzpicture}

\end{document} 

使用引号库来为角度赋值:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}

\newcommand{\tikzAngleOfLine}{\tikz@AngleOfLine}
\def\tikz@AngleOfLine(#1)(#2)#3{%
\pgfmathanglebetweenpoints{%
\pgfpointanchor{#1}{center}}{%
\pgfpointanchor{#2}{center}}
\pgfmathsetmacro{#3}{\pgfmathresult}%
}

\begin{document}

\begin{tikzpicture}[scale=1.5]
\draw (-1,3) coordinate (a_1) -- (3,0) coordinate (a_2);
\draw (-1,2.7) coordinate (b_1) -- (3.5,1) coordinate (b_2);
\coordinate (a) at (intersection of a_1--a_2 and b_1--b_2);    
\fill[red] (a) circle (1pt);
\node[label=below:$r$] at (a) {};
\tikzAngleOfLine(a_1)(a_2){\angle};
\draw[black,->] (a_2) -- ++ (\angle+90:0.3)   
  node[midway,above=0.1cm] {$a$};
\coordinate (aux) at  ([shift={(\angle+90:20pt)}]a_2); 
\draw[<->,>=latex,red] pic["{\tiny$90$}",draw=red,angle radius=8pt]{angle = aux--a_2--a};
\end{tikzpicture}
\end{document} 

箭头的放大图像:

在此处输入图片描述

相关内容