在正六边形内添加点

在正六边形内添加点

在此处输入图片描述

我正在尝试用乳胶创建此图像,并且我特别在正六边形的内部添加了红点,并将正六边形的外边缘变为蓝色。

我可以创建以下正六边形,但我不知道如何将外边缘涂成蓝色或在内部添加点(这些点应该位于对角线的交点上):

\begin{tikzpicture}[
        dot/.style={circle,fill, inner sep=1.5pt, outer sep=0pt},
every label/.style={inner sep=0pt}] 
\newdimen\R
\R=1.3cm
\draw[red]
    (300:\R) \foreach \x in {360,60} {  -- (\x:\R) };
\foreach \i [count=\j] in {1,2,3,4,5,6}
{
    \node (n\j) [dot] at (60*\j:\R) {};
}
\foreach \i in {1,...,6}
{
\ifnum\i=1
    \foreach \j in {2,...,6}
    \draw (n\i) -- (n\j);
\else
   \foreach \j in {\i,...,6}
   \draw (n\i) -- (n\j);
\fi
}
    \end{tikzpicture}

在此处输入图片描述

答案1

就是这样。使用我之前对你的两个问题的回答,这里有一种方法可以找到节点之间定义的线之间的交点:

\node at (intersection of n2--n6 and n1--n3) (A) {};很容易理解。您将节点命名为 n1 到 n6,然后将一个名为 A 的节点(不强制命名,但允许您在之后使用它)放在通过节点 n2 和 n6 的线与通过 n1 和 n3 的线的交点处。

我让你完成剩下的部分。请注意,如果你想缩短代码,也可以使用 foreach 循环来完成它们。

另一个正六边形

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{backgrounds}

\begin{document}

    \begin{tikzpicture}[
        dot/.style={black,circle,fill, inner sep=1.5pt, outer sep=0pt,text=white},
        innode/.style={inner sep=1.5pt,outer sep=0pt,circle,fill=red},
        every label/.style={inner sep=0pt}] 
        \newdimen\R
        \R=1.3cm
        
        \draw[cyan,line width=1pt] (0:\R) \foreach \x [count=\i] in {60,120,...,360} {  -- (\x:\R) node[dot] (n\i) {} };
        
        \begin{scope}[on background layer]      
            \foreach \i in {1,...,6}
                {
                \ifnum\i=1      % Part with \if is useless here, but anyway
                    \foreach \j in {2,...,6}
                    \draw (n\i.center) -- (n\j.center);
                \else
                   \foreach \j in {\i,...,6}
                   \draw (n\i.center) -- (n\j.center);
                \fi
                }       
        \end{scope}

        \node[innode] at (intersection of  n2--n6 and n1--n3) (A) {};
        \node[innode] at (intersection of  n2--n5 and n1--n3) (B) {};
    \end{tikzpicture}
   
\end{document}

答案2

您可能还喜欢元帖子版本,也许?

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
beginfig(1);
    path h;
    h = for t=0 upto 5: 72 dir 60t -- endfor cycle;

    z0 = whatever[point 0 of h, point 2 of h] = whatever[point 1 of h, point 5 of h];
    z1 = whatever[point 0 of h, point 2 of h] = whatever[point 1 of h, point 3 of h];
    z2 = whatever[point 5 of h, point 2 of h] = whatever[point 1 of h, point 3 of h];
    z3 = whatever[point 5 of h, point 3 of h] = whatever[point 2 of h, point 4 of h];
    z4 = whatever[point 5 of h, point 3 of h] = whatever[point 0 of h, point 4 of h];
    z5 = whatever[point 5 of h, point 2 of h] = whatever[point 0 of h, point 4 of h];
    
    draw h withpen pencircle scaled 3 withcolor 3/4[blue, white];
    
    for i=0 upto 5:
        for j=i+1 upto 5:
            draw point i of h -- point j of h;
        endfor
    endfor
    
    for i=0 upto 5:
        drawdot point i of h withpen pencircle scaled 5;
        drawdot z[i]         withpen pencircle scaled 5 withcolor 2/3 red;
    endfor
endfig;
\end{mplibcode}
\end{document}

这被包裹在内luamplib,因此用 进行编译lualatex

相关内容