7

I have the following piece of code and I would like to add two things:

  1. Add a label to the red dot i.e., the intersection of the line segments. Unfortunately, just a ${...}$ does not seem to work.

  2. I want to draw an arrow from the vector a to the line segment showing that the vector is orthogonal to it.

Thank you

\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} 
7
  1. You can use a \node and its label key.

  2. You can use the angles library and its angle pic.

The result:

enter image description here

The code:

\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} 

Using the quotes library to place a value for the angle:

\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} 

A zoomed in image of the arrow:

enter image description here

| improve this answer | |
  • Is the angles library in place by default or should I install it? – Sotiris Kal. Nov 19 '14 at 18:30
  • @SotirisKal. It comes with the latest PGF release (PGF version 3.0). – Gonzalo Medina Nov 19 '14 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.