绘制多边形的奇怪图表 - TiKZ

绘制多边形的奇怪图表 - TiKZ

我画多边形是为了好玩,但我画了一个 100 边的多边形,第 100 个点和第 1 个点连接得不是很好,似乎有些不对劲。这是我的代码:

\documentclass{article}
\usepackage{geometry}
 \geometry{
 a4paper,
 total={200mm,237mm},
 left=5mm,
 top=30mm,
 }
\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage{tkz-euclide,amsmath} 
\usepackage[font=Large,labelfont=bf]{caption}

\usepackage{fancyhdr}
\fancypagestyle{plain}{
\fancyhf{}
\fancyfoot[C]{\large\thepage} 
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}}
\pagestyle{plain}

\begin{document}

\begin{figure}
\centering

\begin{tikzpicture}
\tkzDefPoint(0,0){O}\tkzDefPoint(0,9.5){1}
\tkzDefPointsBy[rotation=center O angle 3.6](1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99){2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100}
\tkzDrawPoints[fill =black,size=4,color=black](1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100)
\tkzDrawPolygon[thick](1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100)
\end{tikzpicture}

\caption{Hectogon/Hecatontagon/Hecatogon}
\end{figure}

\end{document}

有人能帮忙吗?我附上了歪斜部分的图片。

在此处输入图片描述

答案1

无需深入了解tkz-euclide手册,我只需使用循环和极坐标:

\foreach \i in {0, ..., 99} {\tkzDefPoint(90+\i*3.6:9.5){\i}}

我还通过 TikZ 自己的添加了替代解决方案graphs

他们制作了相同的图表。

代码

\documentclass[tikz]{standalone}
\usetikzlibrary{graphs.standard}
\usepackage{tkz-euclide}
\begin{document}
\tikz
  \graph[
    edges=thick,
    nodes={circle, fill, draw, inner sep=+0pt, minimum size=+4pt},
    empty nodes
  ]{ subgraph C_n[n=100, counterclockwise, radius=9.5cm] };

\begin{tikzpicture}
% \tkzDefPoint(0,0){O}
\foreach \i in {0, ..., 99} {\tkzDefPoint(90+\i*3.6:9.5){\i}}
\tkzDrawPoints[fill=black, size=4pt, color=black](0,...,99)
\tkzDrawPolygon[thick](0,...,99)
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

答案2

这是我的下一个“tkz-elements”包的解决方案。测试版已经准备好了,但我还没有完成文档。“tkz-elements”的创建正是为了克服与计算相关的问题。它是一个 Lua 库,用于计算图形所需的点。然后您可以使用 TikZ 或 tkz-euclide 绘制它们。

% !TEX TS-program = lualatex
\documentclass[landscape]{article}
\usepackage{tkz-euclide}
\usepackage{tkz-elements}
\begin{document}
 
 \begin{tkzelements}
   local r = 4
   max = 100
   for i = 1,max 
   do 
      z["A_"..i] = point : polar(r,2*i*math.pi/max)
   end
  set_lua_to_tex{"max"}
\end{tkzelements}
\begin{tikzpicture}
\tkzGetNodes
\tkzDrawPolygon[thick,cyan](A_1,A_...,A_\max)
\tkzDrawPoints[color=black,size=1pt](A_1,A_...,A_\max)
\end{tikzpicture}
\end{document}

\tkzGetNodes将“z”表转换为节点。我仍需解决的问题之一是函数set_lua_to_tex{"max"},它将 Lua 变量“max”转换为 TeX 宏\max。相对危险,因为它是全局的。例如,\max可能会出现问题。alpha

在此处输入图片描述

答案3

让我们玩得开心一点吧!https://www.overleaf.com/read/qkctbkvntstv PS:使用 时n=50,TikZ 会抛出一些错误,而 Asymptote 可以使用n=10000或更多。

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usepackage{asymptote}
\begin{document}
\begin{tikzpicture}[declare function={n=25;},scale=5,c/.style={circle,fill=red,inner sep=3pt}]
\draw (0:1) node[c]{} 
\foreach \i[parse=true] in {1,...,(n)} 
        {--(\i*360/n:1) node[c]{}} --cycle;     
\end{tikzpicture}
\hspace{1cm}
\begin{asy}
// http://asymptote.ualberta.ca/
size(10cm);
int n=50;
pair[] points;
for (int i=0; i<n; ++i)
points.push(dir(360*i/n));
draw(operator--(...points)--cycle);
dot(points,blue+6pt);
//shipout(bbox(5mm,invisible));
\end{asy}
\end{document}

答案4

有 120 个顶点的正多边形

绘制具有 120 个顶点的正多边形。我使用了基本的 Tikz 和库math来获取一些常量(外接圆的半径和点的数量)。

评论它适用于大量顶点,比如 1000 或 2000(参见@Black Mild 的回答)。

代码

\documentclass[11pt, margin=15pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{math}

\begin{document}
\begin{tikzpicture}[p/.style={%
    insert path={%
      node[circle, fill=black, inner sep=.7pt]{}
    }
  },
  evaluate={%
    integer \N; \N = 120;
    real \r; \r = 3;
  }]
  \draw[fill=orange!30] (0: \r) [p]
  \foreach \j in {1, ..., \N}{ -- (\j/\N*360: \r) [p] } -- cycle;
\end{tikzpicture}
\end{document}

相关内容