绘制添加线条和点的正八边形

绘制添加线条和点的正八边形

在此处输入图片描述

这就是我目前正在尝试绘制的。但是我不知道如何添加紫色线条或绿色点。我可以通过以下方式绘制带有点和外线的正八边形:

\begin{tikzpicture} \newdimen\R
   \R=1.3cm
   \draw (0:\R) \foreach \x in {45,90,135,180,225,270,315,360} {  -- (\x:\R) };
   \foreach \x/\l/\p in
     { 45/,
      90/,
      135/,
      180/,
      225/,
      270/,
      315/,
      360
     }
     \node[inner sep=1pt,circle,draw,fill] at (\x:\R) {}; 
\end{tikzpicture}

但我不确定如何添加其余部分。

答案1

正八边形和直线

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

\begin{document}
    \tikzset{
        summit/.style={inner sep=1pt,outer sep=0pt,circle,fill=black,text=white},
        innode/.style={inner sep=1pt,outer sep=0pt,circle,fill=green!50!black,text=white},
        outnode/.style={inner sep=1pt,outer sep=0pt,circle,fill=violet,text=white}
        }
    \begin{tikzpicture}
        \newdimen\R
        \R=1.3cm
        \draw (-22.5:\R) \foreach \x [count=\i] in {0,45,...,315} {  -- (\x+22.5:\R) node[summit] (\i) {} };
        
        \node[innode] at (intersection of  1--6 and 5--8) (A) {};
        \node[innode] at (intersection of  1--4 and 2--5) (B) {};
                
        \node[outnode] at (intersection of  1--2 and 5--4) (C) {};
        \node[outnode] at (intersection of  1--8 and 5--6) (D) {};
        
        \begin{scope}[on background layer]
            \draw[green!50!black]
                (1) -- (6)
                (5) -- (8)
                (1) -- (4)
                (2) -- (5)
                (C) -- (D);
                
            \draw[violet] (C) -- (1) -- (D) -- (5) -- (C);
        \end{scope}
    \end{tikzpicture}

\end{document}

答案2

仅供比较,以下是元帖子,展示如何绘制多边形,以及如何定义直线交点。

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);

    path gon; gon = for i=0 upto 7: 42 dir (45i + 45/2) -- endfor cycle;

    z1 = whatever[point 0 of gon, point 1 of gon] = whatever[point 3 of gon, point 4 of gon];
    z2 = whatever[point 0 of gon, point 3 of gon] = whatever[point 1 of gon, point 4 of gon];
    z3 = whatever[point 0 of gon, point 5 of gon] = whatever[point 7 of gon, point 4 of gon];
    z4 = whatever[point 0 of gon, point 7 of gon] = whatever[point 5 of gon, point 4 of gon];

    drawoptions(withcolor 3/4);
    draw z1 -- z4;
    draw subpath (1,3) of gon -- point 0 of gon -- 
         subpath (5,7) of gon -- point 4 of gon -- cycle;

    drawoptions(withcolor 3/4[red, blue]);
    draw point 0 of gon -- z1 -- point 4 of gon -- z4 -- cycle;

    drawoptions(withpen pencircle scaled dotlabeldiam);
    for i=1 upto 4:
        draw point i of gon;
        draw point i+4 of gon;
        draw z[i] if (i=2) or (i=3): withcolor 1/2 green fi;
    endfor

    drawoptions();
endfig;
\end{mplibcode}
\end{document}

这被包装在 中luamplib,因此您需要用 来编译它lualatex

相关内容