如何访问 \foreach 中的 count 算术值,并在 rotate box{} 中使用它们?

如何访问 \foreach 中的 count 算术值,并在 rotate box{} 中使用它们?

我有一个关于访问 count 的数学值的问题\foreach,我将使用该值在下面的代码中做一些计算。但它不起作用。

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\begin{document}

\begin{tikzpicture}[line cap=round,line join=round,>=triangle    45,x=1.0cm,y=1.0cm]
\clip(-2.5,-3) rectangle (2.5,2.5);
% defining coordinates
\coordinate (origin) at (0,0);
\coordinate (1)      at (0,2);
\coordinate (2)      at ($(origin)!1!120:(1)$);
\coordinate (3)      at ($(origin)!1!120:(2)$);
\coordinate (1_)     at ($(origin)!0.8!-5:(1)$);
\coordinate (2_)     at ($(origin)!0.8!-5:(2)$);
\coordinate (3_)     at ($(origin)!0.8!-5:(3)$);
\coordinate (_1)     at ($(origin)!0.8!5:(1)$);
\coordinate (_2)     at ($(origin)!0.8!5:(2)$);
\coordinate (_3)     at ($(origin)!0.8!5:(3)$);
% draw the circle
\draw [color=black, line width=0.5pt](origin) circle (2 cm);
%draw symmetry elements
\foreach \coordname in {1,2,3}
     \draw [line width=0.5pt, color=black] (\coordname)--     ($(origin)!1!180:(\coordname)$);
\foreach \coordname [count=\i] in {1,2,3}{
     \draw[color=black,font=\large] (\coordname)   node  {\rotatebox{120}{rota}};}
 \draw[color=black,font=\large] (origin)   node {rota};
 % draw plane group notaton
 \draw[color=black] (0,-2.5) node {$222$};
 \end{tikzpicture}
 \end{document}

我需要文本rota根据文本的位置遵循圆的曲线的方向。

然后我添加一些代码:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\begin{document}

\begin{tikzpicture}[line cap=round,line join=round,>=triangle    45,x=1.0cm,y=1.0cm]
\clip(-2.5,-3) rectangle (2.5,2.5);
% defining coordinates
\coordinate (origin) at (0,0);
\coordinate (1)      at (0,2);
\coordinate (2)      at ($(origin)!1!120:(1)$);
\coordinate (3)      at ($(origin)!1!120:(2)$);
\coordinate (1_)     at ($(origin)!0.8!-5:(1)$);
\coordinate (2_)     at ($(origin)!0.8!-5:(2)$);
\coordinate (3_)     at ($(origin)!0.8!-5:(3)$);
\coordinate (_1)     at ($(origin)!0.8!5:(1)$);
\coordinate (_2)     at ($(origin)!0.8!5:(2)$);
\coordinate (_3)     at ($(origin)!0.8!5:(3)$);
% draw the circle
\draw [color=black, line width=0.5pt](origin) circle (2 cm);
%draw symmetry elements
\foreach \coordname in {1,2,3}
     \draw [line width=0.5pt, color=black] (\coordname)--     ($(origin)!1!180:(\coordname)$);
\foreach \coordname [count=\i] in {1,2,3}{
     \pgfmathsetmacro{\n}{\numbers[\i]};  % add
     \draw[color=black,font=\large] (\coordname)   node  {\rotatebox{-120+30*\n}{rota}};}    %some modification
 \draw[color=black,font=\large] (origin)   node {rota};
 % draw plane group notaton
 \draw[color=black] (0,-2.5) node {$222$};
 \end{tikzpicture}
 \end{document}

它不起作用。有人知道这里出了什么问题吗?谢谢

答案1

因此,在您的示例中,您有\numbers[\i],但我不完全确定它指的是什么。我删除了不起作用的代码部分,并尝试查看您正在寻找的内容,以下是我得出的结论:

\documentclass[tikz,convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}    
  \coordinate (origin) at (0,0);

  % draw the circle
  \draw [color=black, line width=0.5pt] (origin) circle (2 cm);

  % draw symmetry elements
  \foreach \coordname [count=\i] in {1,2,...,6} {
    \draw [rotate around={60*\i:(origin)}]
          (origin) -- +(2, 0)
          node [rotate=60*\i, pos=1, right] {rota};
    \coordinate (c\coordname) at ($(origin) + (60*\i:2)$);
  }

  \draw (c1) -- (c2) -- (c3) -- (c4) -- (c5) -- (c6) -- cycle;
\end{tikzpicture}
\end{document}

输出:

输出

我希望这对你来说是一个有用的起点。如果你对其中的某些部分如何工作有任何疑问,请随时发表评论。

答案2

我上传了我对这个问题的解答。

\documentclass[margin=10pt]{standalone}
\DeclareFontFamily{U}{cry}{\hyphenchar\font=-1}
\DeclareFontShape{U}{cry}{m}{n}{ <-> cryst}{}
\newcommand{\cry}[1]{{\usefont{U}{cry}{m}{n} \symbol{#1}}}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\clip(-2.5,-3) rectangle (2.5,2.5);
% defining coordinates
\coordinate (origin) at (0,0);
\coordinate (1)      at (0,2);
\coordinate (2)      at ($(origin)!1!120:(1)$);
\coordinate (3)      at ($(origin)!1!120:(2)$);
% draw the circle
\draw [color=black, line width=0.5pt](origin) circle (2 cm);
%draw symmetry elements
\foreach \coordname in {1,2,3}
    \draw [line width=0.5pt, color=black] (\coordname)-- ($(origin)!1!180:(\coordname)$);
\foreach \coordname [count=\i] in {1,2,3}{
    \draw[color=black,font=\large] (\coordname)  node [rotate=-210+120*\i] {\cry{2}};
    \draw[color=black,font=\large] ($(origin)!-1!(\coordname)$)  node [rotate=-210+120*\i] {\cry{2}};
}
\draw[color=black,font=\large] (origin)   node {\cry{3}};
% draw plane group notaton
\draw[color=black] (0,-2.5) node {$32$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容