4

I would like to replicate the following figure: Morley Element Degrees of Freedom

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?

Shuhao Cao
  • 3,131
  • 3
  • 29
  • 33

4 Answers4

10

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}
Jake
  • 232,450
7

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}

enter image description here

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}

enter image description here

percusse
  • 157,807
3

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}
\tkzDefPoint(\radius,0){B}
\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}
N3buchadnezzar
  • 11,348
  • 7
  • 55
  • 114
3

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} 

enter image description here

Alain Matthes
  • 95,075
  • 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 06: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 07: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 07:14
  • Yes I agree with you but it's easy to calculate the angles from the corners ... – Alain Matthes Jul 18 '12 at 07:35