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} 
5
  • 1
    For 1), use something like \node[label=below:$r$] at (a) {};. For 2), how should that desired arrow be? (an arrow in the shape of an arc or something else?). Commented Nov 19, 2014 at 18:03
  • It should be something like the red arrow as in the accepted answer tex.stackexchange.com/questions/20826/label-angle-with-tikz Commented Nov 19, 2014 at 18:06
  • ooopss. Edited :) Commented Nov 19, 2014 at 18:08
  • Also, your suggestion for the label doesn't seem to output anything Commented Nov 19, 2014 at 18:10
  • Please see my answer below. Commented Nov 19, 2014 at 18:19

1 Answer 1

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

2
  • Is the angles library in place by default or should I install it? Commented Nov 19, 2014 at 18:30
  • @SotirisKal. It comes with the latest PGF release (PGF version 3.0). Commented Nov 19, 2014 at 18:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .