# how to draw a regular hexagon with some additional lines

I'm writing because I need to draw a regular hexagon with a few more lines as in the picture attached.

I know how to draw a hexagon, here is my code

\documentclass[border=2mm]{standalone}
\usepackage{ifthen}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\newdimen\R
\R=4cm
\draw[thick] (330:\R) \foreach \x in {30,90,...,330} {  -- (\x:\R) };
%\fill [black] (30:\R) circle (3pt);
\foreach \x in {30,150,270}
{
\draw[line width=0.5pt,black,fill=white] (\x:\R) circle (3pt);
}
\foreach \x in {90,210,330}
{
\draw[line width=0.5pt,black,fill=black] (\x:\R) circle (3pt);
}
%\draw (90:\R) [out=0, in=180] (10,1);
\end{tikzpicture}
\end{document}


It works but I don't know how to add lines because I need point coordinates for that and I'm in trouble because I don't have a clear reference for the vertices. The picture I'd like to draw is something like this

The quality is not good, the longest curve is red and the other two curves are green.

Can anyone help me?

You can use polar coordinates with the shift option. This in combiation with scopes should make it relatively easy to get the coorinates right in this hexagonal setting:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\newdimen\R
\R=4cm
\draw[thick] (330:\R) foreach \x in {30,90,...,330} { -- (\x:\R) };
%\fill [black] (30:\R) circle (3pt);
\foreach \x in {30,150,270} {
\draw[dashed] (\x:\R) -- (\x:{\R+3cm});
\draw[line width=0.5pt,black,fill=white] (\x:\R) circle (3pt);
}
\foreach \x in {90,210,330} {
\draw[line width=0.5pt,black,fill=black] (\x:\R) circle (3pt);
}
%\draw (90:\R) [out=0, in=180] (10,1);

\begin{scope}[shift=(150:\R)]
\draw[thick, green, rounded corners=5pt]
(30:1cm) -- (90:1cm) -- (150:1cm) -- (210:1cm) -- (270:1cm);
\end{scope}

\begin{scope}[shift=(330:\R)]
\draw[thick, green, rounded corners=5pt]
(210:3cm) -- ([shift=(330:1cm)]210:3cm) -- (330:1cm) -- ([shift=(330:1cm)]90:3cm) -- (90:3cm);
\end{scope}

\begin{scope}[shift=(30:\R)]
\draw[thick, red, rounded corners=5pt]
([shift=(210:2cm)]150:4cm) -- ([shift=(150:2cm)]150:4cm) -- ([shift=(90:2cm)]150:4cm) -- (30:2cm) -- ([shift=(330:2cm)]270:4cm) -- ([shift=(270:2cm)]270:4cm) -- ([shift=(210:2cm)]270:4cm);
\end{scope}

\end{tikzpicture}
\end{document}


Alternative where the colored lines meet at right angle with the hexagon:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\newdimen\R
\R=4cm
\draw[thick] (330:\R) foreach \x in {30,90,...,330} { -- (\x:\R) };
%\fill [black] (30:\R) circle (3pt);
\foreach \x in {30,150,270} {
\draw[dashed] (\x:\R) -- (\x:{\R+3cm});
\draw[line width=0.5pt,black,fill=white] (\x:\R) circle (3pt);
}
\foreach \x in {90,210,330} {
\draw[line width=0.5pt,black,fill=black] (\x:\R) circle (3pt);
}
%\draw (90:\R) [out=0, in=180] (10,1);

\begin{scope}[shift=(150:\R)]
\draw[thick, green, rounded corners=5pt]
(30:.5cm) -- (90:1cm) -- (150:1cm) -- (210:1cm) -- (270:.5cm);
\end{scope}

\begin{scope}[shift=(330:\R)]
\draw[thick, green, rounded corners=5pt]
(210:2.5cm) -- ([shift=(330:1cm)]210:3cm) -- (330:1cm) -- ([shift=(330:1cm)]90:3cm) -- (90:2.5cm);
\end{scope}

\begin{scope}[shift=(30:\R)]
\draw[thick, red, rounded corners=5pt]
([shift=(210:1cm)]150:4cm) -- ([shift=(150:2cm)]150:4cm) -- ([shift=(90:2cm)]150:4cm) -- (30:2cm) -- ([shift=(330:2cm)]270:4cm) -- ([shift=(270:2cm)]270:4cm) -- ([shift=(210:1cm)]270:4cm);
\end{scope}

\end{tikzpicture}
\end{document}


Here is a Metapost alternative, purely for comparison.

This is wrapped up in luamplib so compile it with lualatex.

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}

vardef rounded_corners expr p =
point 0 of p for t=1 upto length p:
.. (subpath (t-1, t) of p
cutbefore fullcircle scaled 5 shifted point t-1 of p
cutafter  fullcircle scaled 5 shifted point t of p)
endfor .. point infinity of p
enddef;

beginfig(1);
% define the base hexagon
numeric r; r = 50;
path h; h = for t=0 upto 5: up scaled r rotated 60t -- endfor cycle;

% mark the three sectors
for m = (0.8, 1.2, 10), (3.25, 4.75, 10), (3.7, 6.3, 20):
numeric a, b, c; path g;
a = redpart m; b = greenpart m; c = bluepart m;
% build the sector path
g = subpath (a, b) of h scaled (1 + c/r);
g := (up -- origin) scaled r rotated angle direction 0 of g
shifted point 0 of g cutbefore h & g;
g := g & ((origin -- up) scaled r rotated angle direction infinity of g
shifted point infinity of g cutafter h);
% draw it with rounded corners
draw rounded_corners g
if c=10: withcolor 2/3 green elseif c=20: withcolor 2/3 red fi;
endfor

% draw the hexagon and mark the vertices
draw h;
for i=0 upto 5:
if odd i:
draw point i of h -- 2 point i of h dashed evenly;
fi
draw point i of h withpen pencircle scaled 3;
if odd i:
draw point i of h withpen pencircle scaled 2 withcolor white;
fi
endfor
endfig;
\end{mplibcode}
\end{document}


Here's a calc powered solution.

At the end of the day, this allows you to do

\draw [red] [around hex={1-2 / 1, 6, 5 / 5-4}];


to draw that line from the edge between corner 1 and 2 (which means the length of Indent from corner 1 to corner 2), around corners 1, 6 and 5 and back to the edge between corner 2 and 1.

There are three parts to your path around the hexagons:

1. from the edges of your hexagon away from it (up from),
2. to the points above the corners (above corner) and
3. back to edge (down to).

The key up from = <c1>-<c2> draws a line from the point that is Indent away from <c1> to <c2> up (orthogonally) to the point that is cos(30°) * Distance "above" the hexagon.

The down to key draws the same path but in reverse.

And the key above corner = <c> draws a line to the corner that is Distance "above" the corner <c>.

The key around hex = <up from> / <corner list> / <down to> combines these three parts in one key.

I've added a fourth line that does not use around hex but permits changed to the distances.

## Code

\documentclass[border=2mmm, tikz]{standalone}
\usetikzlibrary{shapes.geometric,calc}
\begin{document}
\begin{tikzpicture}[
thick, rounded corners,
%
main/.style={% this is the polygon, it's a shape
draw=black, name=hex,
shape=regular polygon, regular polygon sides=6, minimum size=8cm, rotate=30},
corner/.style={% these are the circles at the corners, they're sahpes, too.
draw=black, shape=circle, minimum size=6pt,
at=(hex.corner #1), node contents=},% , label=#1
%
% default values for …
Indent/.initial=10mm,  % … the distance from the corner to the line
Distance/.initial=10mm,% … from the polygon to the lines around it
%
% draws a line from the point that is Indent away from corner #1 to corner #2
% to the point that lies Distance away from that point orthogonally
% to the line between corner #1 and corner #2°
up from/.style args={#1-#2}{
insert path={
($(hex.corner #1)!\pgfkeysvalueof{/tikz/Indent}!(hex.corner #2)$) --
($(hex.corner #1)!\pgfkeysvalueof{/tikz/Indent}!(hex.corner #2)! .86602540 * sign(#1 - #2) * (abs(#1 - #2) == 5 ? -1 : 1) * \pgfkeysvalueof{/tikz/Distance}!90:(hex.corner #2)$)}},
%
% the same as "up from" just reversed
down to/.style args={#1-#2}{
insert path={ --
($(hex.corner #1)!\pgfkeysvalueof{/tikz/Indent}!(hex.corner #2)! .86602540 * sign(#1 - #2) * (abs(#1 - #2) == 5 ? -1 : 1) * \pgfkeysvalueof{/tikz/Distance}!90:(hex.corner #2)$) --
($(hex.corner #1)!\pgfkeysvalueof{/tikz/Indent}!(hex.corner #2)$)}},
%
% draws a line to the point Distance away from corner #1 "above" the hexagon
% i.e. away from the center
above corner/.value required,
above corner/.style={insert path={% Distance away from corner #1
-- ($(hex.corner #1)!\pgfkeysvalueof{/tikz/Distance}!180:(hex.center)$)}},
%
% all together
around hex/.style args={#1/#2/#3}{
up from=#1, above corner/.list={#2}, down to=#3}]

\node[main] {};
\foreach \cor[evaluate={\col=mod(\cor,2)?"black":"white";}] in {1,...,6}
\node[corner=\cor, fill=\col];

\draw [red] [around hex={1-2 / 1, 6, 5 / 5-4}];
\draw [green, Distance=7.5mm] [around hex={6-5 / 5 / 4-5}]
[around hex={2-1 / 2 / 2-3}];
\draw [dashed, Indent=15mm, Distance=15mm]
[up from=1-6, above corner=6, Indent=5mm, down to=6-5];
\end{tikzpicture}
\end{document}