I've programmed a little code that will take a regular polygon and rotates it a bit smaller, then rotates it a bit smaller, etc. I'm sure you've seen something like it on the net. (You'll see what it is supposed to look like below.)
But something odd is happening. When I create the polygons (hexagons in this case) doing it case by case, it works just like it's supposed to:
Code: Select all
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfmath}
\usetikzlibrary{intersections}
\begin{document}
\newcommand\nextr[3]{
\path[name path=outer] (#3:#2) -- ({#3+360/\n}:#2);
\pgfmathsetmacro{\ang}{#1*5}
\path[name path=radial] (O) -- (#3:#2);
\path[name intersections={of=outer and radial,by=a}];
\path[transform canvas] (a);
\pgfgetlastxy{\xcoord}{\ycoord}
\pgfmathsetmacro{\Xcoord}{scalar{\xcoord}/28.452756}
\pgfmathsetmacro{\Ycoord}{scalar{\ycoord}/28.452756}
\def\x{\Xcoord}
\def\y{\Ycoord}
\pgfmathsetmacro{\r}{sqrt((\x)^2+(\y)^2)}
}
\def\n{6}
\def\r{8}
\def\ang{0}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\draw (0:\r) foreach \t in {1,...,\n} { -- ({\t*(360/\n)}:\r) };
\def\s{1}
\nextr{1}{\r}{\ang};
\draw (\ang:\r) foreach \t in {1,...,\n} { -- ({\ang+\t*(360/\n)}:\r) };
\def\s{2}
\nextr{2}{\r}{\ang};
\draw (\ang:\r) foreach \t in {1,...,\n} { -- ({\ang+\t*(360/\n)}:\r) };
\def\s{3}
\nextr{3}{\r}{\ang};
\draw (\ang:\r) foreach \t in {1,...,\n} { -- ({\ang+\t*(360/\n)}:\r) };
\def\s{4}
\nextr{4}{\r}{\ang};
\draw (\ang:\r) foreach \t in {1,...,\n} { -- ({\ang+\t*(360/\n)}:\r) };
\def\s{5}
\nextr{5}{\r}{\ang};
\draw (\ang:\r) foreach \t in {1,...,\n} { -- ({\ang+\t*(360/\n)}:\r) };
\def\s{6}
\nextr{6}{\r}{\ang};
\draw (\ang:\r) foreach \t in {1,...,\n} { -- ({\ang+\t*(360/\n)}:\r) };
\end{tikzpicture}
\end{document}
Code: Select all
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfmath}
\usetikzlibrary{intersections}
\begin{document}
\newcommand\nextr[3]{
\path[name path=outer] (#3:#2) -- ({#3+360/\n}:#2);
\pgfmathsetmacro{\ang}{#1*5}
\path[name path=radial] (O) -- (#3:#2);
\path[name intersections={of=outer and radial,by=a}];
\path[transform canvas] (a);
\pgfgetlastxy{\xcoord}{\ycoord}
\pgfmathsetmacro{\Xcoord}{scalar{\xcoord}/28.452756}
\pgfmathsetmacro{\Ycoord}{scalar{\ycoord}/28.452756}
\def\x{\Xcoord}
\def\y{\Ycoord}
\pgfmathsetmacro{\r}{sqrt((\x)^2+(\y)^2)}
}
\def\n{6}
\def\r{8}
\def\ang{0}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\draw (0:\r) foreach \t in {1,...,\n} { -- ({\t*(360/\n)}:\r) };
\foreach \s in {1,...,5}{
\nextr{\s}{\r}{\ang};
\draw (\ang:\r) foreach \t in {1,...,\n} { -- ({\ang+\t*(360/\n)}:\r) };
};
\end{tikzpicture}
\end{document}
What gives? (This reminds me of the time I programmed a timer in machine code for 10 seconds... It was running too slow and I couldn't figure it out. Finally, someone pointed out that I had programmed it to count to 10 instead of to A.)
Thanks!
-Dan