如何存取\foreach中count的算術值,並在rotate box{}中使用它們?

如何存取\foreach中count的算術值,並在rotate box{}中使用它們?

我有一個關於訪問 count in 的數學值的問題\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}

在此輸入影像描述

相關內容