I've uploading the picture I'm trying to replicate. (It's the one at the top left.) The code I'm posting below can sketch all 7 curves, but I've limited the loop to only sketch the inner loop, for clarity. I've broken it down into a smaller picture that I'm going to rotate about the origin 7 times, but when I rotate the picture, it rotates about the "wrong" point. (The first code below is the picture I'm going to rotate about the point O below it. The second code is what happens when I actually do the rotation.)
To break this down a bit more simply, in a nutshell, the code does this:
[whole bunch of calculations]
\draw (1) arc(...) arc(...);
When I include a rotation
\foreach \w in {0,...,6}{
\begin{scope}[rotate=\w*360/7]
[whole bunch of calculations]
\draw (1) arc(...) arc(...);
\end{scope}
}:
the picture rotates about the point (1). How do I define the center of rotation to be the point (0,0)? I mean, I could do the rotation manually, but the code is already much longer than I had originally thought it would be for so simple an image. And I'm curious to see how it can be done this way.
Thanks!
-Dan
Single curve:
Code: Select all
\documentclass{article}
\usepackage{tikz}
\usepackage{etoolbox}
\usetikzlibrary{intersections}
\begin{document}
\newcommand\coords[1]{
\path[transform canvas] (#1);
\pgfgetlastxy{\xcoord}{\ycoord}
\pgfmathsetmacro{\Xcoord}{scalar{\xcoord}/28.452756}
\pgfmathsetmacro{\Ycoord}{scalar{\ycoord}/28.452756}
\xdef\x{\Xcoord}
\xdef\y{\Ycoord}
}
\def\n{7}
\def\r{1}
\def\R{6}
\pgfmathsetmacro{\t}{360/\n}
\pgfmathsetmacro{\A}{90-\t/2}
\pgfmathsetmacro{\f}{cot(\t)/2}
\pgfmathsetmacro{\p}{\R*sqrt(2-2*cos(\t))-\r}
\pgfmathsetmacro{\d}{\R*sqrt(2-2*cos(\t)}
\pgfmathsetmacro{\step}{(\p-\r)/(\n-1)}
\begin{tikzpicture}
\coordinate[label={O}] (O) at (0,0); \fill (O) circle(2pt);
\coordinate (aI) at (90:\R);;
\coordinate (aII) at ({90+\t}:\R);
\coordinate (aIII) at ({90+2*\t}:\R);
\coordinate (aVII) at ({90+6*\t}:\R);
\coords{aI}; \pgfmathsetmacro{\aIx}{\x} \pgfmathsetmacro{\aIy}{\y}
\coords{aII}; \pgfmathsetmacro{\aIIx}{\x} \pgfmathsetmacro{\aIIy}{\y}
\coords{aIII}; \pgfmathsetmacro{\aIIIx}{\x} \pgfmathsetmacro{\aIIIy}{\y}
\coords{aVII}; \pgfmathsetmacro{\aVIIx}{\x} \pgfmathsetmacro{\aVIIy}{\y}
\foreach \w in {0,...,0}{
\begin{scope}[rotate=\w*\t]
\foreach \s in {1,...,1}{
\pgfmathsetmacro{\mI}{\s}
\pgfmathsetmacro{\mII}{7}
\pgfmathsetmacro{\mIII}{8-\s}
\pgfmathsetmacro{\mIV}{7}
\pgfmathsetmacro{\tempradI}{\r+(\mI-1)*\step}
\pgfmathsetmacro{\tempradII}{\r+(\mII-1)*\step}
\pgfmathsetmacro{\tempradIII}{\r+(\mIII-1)*\step}
\pgfmathsetmacro{\tempradIV}{\r+(\mIV-1)*\step}
\path[name path=I] (aI) circle(\tempradI);
\path[name path=II] (aVII) circle(\tempradII);
\path[name path=III] (aII) circle(\tempradIII);
\path[name path=IV] (aIII) circle(\tempradIV);
\path[name intersections={of=I and II,name=i}]; \coordinate (1) at (i-1);
\path[name intersections={of=I and III,name=i}]; \coordinate (2) at (i-1);
\path[name intersections={of=III and IV,name=i}]; \coordinate (3) at (i-2);
\coords{1}; \pgfmathsetmacro{\xI}{\x} \pgfmathsetmacro{\yI}{\y}
\coords{2}; \pgfmathsetmacro{\xII}{\x} \pgfmathsetmacro{\yII}{\y}
\coords{3}; \pgfmathsetmacro{\xIII}{\x} \pgfmathsetmacro{\yIII}{\y}
\pgfmathsetmacro{\slopeI}{-(\xI-\aIx)/(\yI-\aIy))}
\pgfmathanglebetweenlines{\pgfpoint{-0.5}{0}}{\pgfpoint{0.5}{0}}
{\pgfpoint{\xI+0.5}{\slopeI*((\xI+0.5)-\xI)+\yI}}{\pgfpoint{\xI-0.5}{\slopeI*((\xI-0.5)-\xI)+\yI}}
\ifnum \s=1 \pgfmathsetmacro{\angI}{\pgfmathresult-270}
\else \pgfmathsetmacro{\angI}{\pgfmathresult-90}
\fi
\pgfmathsetmacro{\slopeII}{-(\xII-\aIx)/(\yII-\aIy))}
\pgfmathanglebetweenlines{\pgfpoint{-0.5}{0}}{\pgfpoint{0.5}{0}}
{\pgfpoint{\xII+0.5}{\slopeII*((\xII+0.5)-\xII)+\yII}}{\pgfpoint{\xII-0.5}{\slopeII*((\xII-0.5)-\xII)+\yII}}
\pgfmathsetmacro{\angII}{\pgfmathresult+90}
\pgfmathsetmacro{\slopeIIa}{-(\xII-\aIIx)/(\yII-\aIIy))}
\pgfmathanglebetweenlines{\pgfpoint{-0.5}{0}}{\pgfpoint{0.5}{0}}
{\pgfpoint{\xII+0.5}{\slopeIIa*((\xII+0.5)-\xII)+\yII}}{\pgfpoint{\xII-0.5}{\slopeIIa*((\xII-0.5)-\xII)+\yII}}
\pgfmathsetmacro{\angIIa}{\pgfmathresult+270}
\pgfmathsetmacro{\slopeIII}{-(\xIII-\aIIx)/(\yIII-\aIIy))}
\pgfmathanglebetweenlines{\pgfpoint{-0.5}{0}}{\pgfpoint{0.5}{0}}
{\pgfpoint{\xIII+0.5}{\slopeIII*((\xIII+0.5)-\xIII)+\yIII}}{\pgfpoint{\xIII-0.5}{\slopeIII*((\xIII-0.5)-\xIII)+\yIII}}
\pgfmathsetmacro{\angIII}{\pgfmathresult+90}
\draw[red,thick] (1) arc(\angI:\angII:\tempradI) arc(\angIIa:\angIII:\tempradIII);
};
\end{scope}
};
\end{tikzpicture}
\end{document}
Code: Select all
\documentclass{article}
\usepackage{tikz}
\usepackage{etoolbox}
\usetikzlibrary{intersections}
\begin{document}
\newcommand\coords[1]{
\path[transform canvas] (#1);
\pgfgetlastxy{\xcoord}{\ycoord}
\pgfmathsetmacro{\Xcoord}{scalar{\xcoord}/28.452756}
\pgfmathsetmacro{\Ycoord}{scalar{\ycoord}/28.452756}
\xdef\x{\Xcoord}
\xdef\y{\Ycoord}
}
\def\n{7}
\def\r{1}
\def\R{6}
\pgfmathsetmacro{\t}{360/\n}
\pgfmathsetmacro{\A}{90-\t/2}
\pgfmathsetmacro{\f}{cot(\t)/2}
\pgfmathsetmacro{\p}{\R*sqrt(2-2*cos(\t))-\r}
\pgfmathsetmacro{\d}{\R*sqrt(2-2*cos(\t)}
\pgfmathsetmacro{\step}{(\p-\r)/(\n-1)}
\begin{tikzpicture}
\coordinate[label={O}] (O) at (0,0); \fill (O) circle(2pt);
\coordinate (aI) at (90:\R);;
\coordinate (aII) at ({90+\t}:\R);
\coordinate (aIII) at ({90+2*\t}:\R);
\coordinate (aVII) at ({90+6*\t}:\R);
\coords{aI}; \pgfmathsetmacro{\aIx}{\x} \pgfmathsetmacro{\aIy}{\y}
\coords{aII}; \pgfmathsetmacro{\aIIx}{\x} \pgfmathsetmacro{\aIIy}{\y}
\coords{aIII}; \pgfmathsetmacro{\aIIIx}{\x} \pgfmathsetmacro{\aIIIy}{\y}
\coords{aVII}; \pgfmathsetmacro{\aVIIx}{\x} \pgfmathsetmacro{\aVIIy}{\y}
\foreach \w in {0,...,2}{
\begin{scope}[rotate=\w*\t]
\foreach \s in {1,...,1}{
\pgfmathsetmacro{\mI}{\s}
\pgfmathsetmacro{\mII}{7}
\pgfmathsetmacro{\mIII}{8-\s}
\pgfmathsetmacro{\mIV}{7}
\pgfmathsetmacro{\tempradI}{\r+(\mI-1)*\step}
\pgfmathsetmacro{\tempradII}{\r+(\mII-1)*\step}
\pgfmathsetmacro{\tempradIII}{\r+(\mIII-1)*\step}
\pgfmathsetmacro{\tempradIV}{\r+(\mIV-1)*\step}
\path[name path=I] (aI) circle(\tempradI);
\path[name path=II] (aVII) circle(\tempradII);
\path[name path=III] (aII) circle(\tempradIII);
\path[name path=IV] (aIII) circle(\tempradIV);
\path[name intersections={of=I and II,name=i}]; \coordinate (1) at (i-1);
\path[name intersections={of=I and III,name=i}]; \coordinate (2) at (i-1);
\path[name intersections={of=III and IV,name=i}]; \coordinate (3) at (i-2);
\coords{1}; \pgfmathsetmacro{\xI}{\x} \pgfmathsetmacro{\yI}{\y}
\coords{2}; \pgfmathsetmacro{\xII}{\x} \pgfmathsetmacro{\yII}{\y}
\coords{3}; \pgfmathsetmacro{\xIII}{\x} \pgfmathsetmacro{\yIII}{\y}
\pgfmathsetmacro{\slopeI}{-(\xI-\aIx)/(\yI-\aIy))}
\pgfmathanglebetweenlines{\pgfpoint{-0.5}{0}}{\pgfpoint{0.5}{0}}
{\pgfpoint{\xI+0.5}{\slopeI*((\xI+0.5)-\xI)+\yI}}{\pgfpoint{\xI-0.5}{\slopeI*((\xI-0.5)-\xI)+\yI}}
\ifnum \s=1 \pgfmathsetmacro{\angI}{\pgfmathresult-270}
\else \pgfmathsetmacro{\angI}{\pgfmathresult-90}
\fi
\pgfmathsetmacro{\slopeII}{-(\xII-\aIx)/(\yII-\aIy))}
\pgfmathanglebetweenlines{\pgfpoint{-0.5}{0}}{\pgfpoint{0.5}{0}}
{\pgfpoint{\xII+0.5}{\slopeII*((\xII+0.5)-\xII)+\yII}}{\pgfpoint{\xII-0.5}{\slopeII*((\xII-0.5)-\xII)+\yII}}
\pgfmathsetmacro{\angII}{\pgfmathresult+90}
\pgfmathsetmacro{\slopeIIa}{-(\xII-\aIIx)/(\yII-\aIIy))}
\pgfmathanglebetweenlines{\pgfpoint{-0.5}{0}}{\pgfpoint{0.5}{0}}
{\pgfpoint{\xII+0.5}{\slopeIIa*((\xII+0.5)-\xII)+\yII}}{\pgfpoint{\xII-0.5}{\slopeIIa*((\xII-0.5)-\xII)+\yII}}
\pgfmathsetmacro{\angIIa}{\pgfmathresult+270}
\pgfmathsetmacro{\slopeIII}{-(\xIII-\aIIx)/(\yIII-\aIIy))}
\pgfmathanglebetweenlines{\pgfpoint{-0.5}{0}}{\pgfpoint{0.5}{0}}
{\pgfpoint{\xIII+0.5}{\slopeIII*((\xIII+0.5)-\xIII)+\yIII}}{\pgfpoint{\xIII-0.5}{\slopeIII*((\xIII-0.5)-\xIII)+\yIII}}
\pgfmathsetmacro{\angIII}{\pgfmathresult+90}
\draw[red,thick] (1) arc(\angI:\angII:\tempradI) arc(\angIIa:\angIII:\tempradIII);
};
\end{scope}
};
\end{tikzpicture}
\end{document}