# Drawing outward normal vectors to a regular polygon without specifying the coordinates

I would like to replicate the following figure:

And I tried using rotate to circumvent using a specific coordinate together with the predefined anchor for regular polygon, and apparently it doesn't work.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
\node[regular polygon, regular polygon sides=3, draw, minimum size=4cm]
(m) at (0,0) {};

\fill [black] (m.corner 1) circle (3pt);
\draw [black] (m.corner 1) circle (6pt);

\fill [black] (m.corner 2) circle (3pt);
\draw [black] (m.corner 2) circle (6pt);

\fill [black] (m.corner 3) circle (3pt);
\draw [black] (m.corner 3) circle (6pt);

\draw [black, ->, rotate=-90] (m.side 1) -- (m.corner 1);

\end{tikzpicture}
\end{document}


It appears to me that if I named the starting point and ending point for draw using the anchors, then the rotate wouldn't work?

-
Please extend your code snippet to a complete document. –  Gonzalo Medina Jul 17 '12 at 19:20
possible duplicate of How to draw orthogonal vectors using TikZ –  Jake Jul 17 '12 at 19:21
The reason your attempt of drawing the normals using a rotate key in the draw command didn't work is that node anchor coordinates aren't transformed by draw or shift keys. It does work with explicitly specified coordinates (try \draw [rotate=45] (0,0) -- (1,0);). –  Jake Jul 17 '12 at 19:41
@Jake, thanks a lot. –  Shuhao Cao Jul 17 '12 at 19:44

You can use the calc library with the partway syntax, which accepts an optional rotation argument.

The expression

($(A)!0.5!90:(B)$)


specifies the point that lies half the distance between (A) and (B) away from (A) in the direction 90 degrees rotated from the direction between (A) and (B).

In your case, you could draw the normal to side 1 using

\draw [-latex, thick] (m.side 1) -- ($(m.side 1)!0.5!90:(m.corner 1)$);


\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, calc}

\begin{document}
\begin{tikzpicture}
\node[regular polygon, regular polygon sides=3, draw, minimum size=4cm]
(m) at (0,0) {};

\fill [black] (m.corner 1) circle (3pt);
\draw [black] (m.corner 1) circle (6pt);

\fill [black] (m.corner 2) circle (3pt);
\draw [black] (m.corner 2) circle (6pt);

\fill [black] (m.corner 3) circle (3pt);
\draw [black] (m.corner 3) circle (6pt);

\draw [-latex, thick] (m.side 1) -- ($(m.side 1)!0.5!90:(m.corner 1)$);
\draw [-latex, thick] (m.side 2) -- ($(m.side 2)!0.5!90:(m.corner 2)$);
\draw [-latex, thick] (m.side 3) -- ($(m.side 3)!0.5!90:(m.corner 3)$);

\end{tikzpicture}

\end{document}

-

I think these arrow tips are not predefined in TikZ. But can be defined from scratch if important.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[regular polygon, regular polygon sides=3, draw, minimum size=4cm,thick] (m) at (0,0) {};

\foreach \x[count=\xi from 0] in {1,2,3}{
\fill [black,thick] (m.corner \x) circle (3pt);
\draw [black,thick] (m.corner \x) circle (6pt);
\draw [black,thick,->] (m.side \x) -- (\xi*120+150:2cm);
};

\end{tikzpicture}
\end{document}


By adding the calc library, one can also use the geometric center with similar syntax given in Jake's answer for rotation-awareness (also works for more sides too).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, calc}
\begin{document}
\begin{tikzpicture}[rotate=45,transform shape]
\node[regular polygon, regular polygon sides=3, draw, minimum size=4cm,thick] (m) at (0,0) {};
\foreach \x in {1,2,3}{
\fill [black,thick] (m.corner \x) circle (3pt);
\draw [black,thick] (m.corner \x) circle (6pt);
\draw [black,thick,->] (m.side \x) -- ($(m.side \x)!-1!(m.center)$);
};
\end{tikzpicture}
\end{document}


-
@Jake Ah, OK! I think there is also another solution let me try it. –  percusse Jul 17 '12 at 19:49
Ah yes, very nice! –  Jake Jul 17 '12 at 19:56

Solution with tikz-euclide, can of course be improved =)

\documentclass{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}

\begin{tikzpicture}[rotate=10]
\def\radius{10} % Defines the size (sidelength of the triangle)
\def\T{0.20}     % Defines the thickness of the figure
\pgfmathsetmacro{\E}{\radius/16} % Macro for drawing the filled circles
\pgfmathsetmacro{\r}{\radius/8}   % Macro for drawing the circles.

\tkzDefPoint(0,0){A}
\tkzDefPointBy[rotation= center A angle 60](B)
\tkzGetPoint{C}
\tkzCentroid(A,B,C)    \tkzGetPoint{O}
\tkzDefMidPoint(A,B)  \tkzGetPoint{M1}
\tkzDefMidPoint(A,C)  \tkzGetPoint{M2}
\tkzDefMidPoint(B,C)  \tkzGetPoint{M3}
\tkzInterLC(A,O)(O,B) \tkzGetSecondPoint{T1}
\tkzInterLC(B,O)(O,B) \tkzGetSecondPoint{T2}
\tkzInterLC(C,O)(O,C) \tkzGetSecondPoint{T3}

\tkzDrawPolygon[line width=\T cm](A,B,C)
\tkzDrawCircle[R,line width=\T cm](A,\r cm) \tkzDrawCircle[R, fill=black](A,\E cm)
\tkzDrawCircle[R,line width=\T cm](B,\r cm) \tkzDrawCircle[R, fill=black](B,\E cm)
\tkzDrawCircle[R,line width=\T cm](C,\r cm) \tkzDrawCircle[R, fill=black](C,\E cm)
\tkzDrawSegments[-stealth,line width = \T cm](M3,T1 M2,T2 M1,T3)
\end{tikzpicture}

\end{document}

-

I don't understand the request : without-specifying-the-coord You need to use coordinates and in the first answers ($(A)!0.5!90:(B)$) or ($(m.side \x)!-1!(m.center)$) uses coordinates. A simple possibility is with some coordinates , without libraries:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture} [-latex,ultra thick]
\draw[fill] (-30:4) circle (3pt) -- (90:4) circle (3pt) -- (210:4) circle (3pt) -- (-30:4);
\draw (-30:4) circle (6pt)  (90:4) circle (6pt)  (210:4) circle (6pt) ;
\draw[->] (30:2)  -- (30:4);
\draw[->] (150:2) -- (150:4);
\draw[->] (270:2) -- (270:4);
\end{tikzpicture}
\end{document}


-
I think what the OP means by "without specifying the coordinates" is that he doesn't want to manually find the coordinates of the arrows, but only specify which side to draw the normals to. –  Jake Jul 18 '12 at 6:15
yes but with a regular polygon, we can say that the coordinates of the arrows are given by the corners of the polygon... The question is more interesting with an irregular polygon. –  Alain Matthes Jul 18 '12 at 7:08
The question is definitely more interesting with an irregular polygon, or with a general straight line. However, even in the case of a regular polygon, I wouldn't say the "coordinates of the arrows are given by the corners of the polygon". They're given by the line between the corners of the polygon, rotated by 90 degrees. In your solution, one needs to manually enter the angle for the arrows, while percusse's and mine don't need that information. –  Jake Jul 18 '12 at 7:14
Yes I agree with you but it's easy to calculate the angles from the corners ... –  Alain Matthes Jul 18 '12 at 7:35