foreach 자체가 아닌 foreach의 출력 가져오기

foreach 자체가 아닌 foreach의 출력 가져오기

변수에 저장된 다음 매크로의 출력을 얻고 싶습니다.

\foreach \m in {1,...,9}{\csname h\m \endcsname};

나는 다음을 시도했습니다.

\def\lkj{
  \foreach \m in {1,...,9}{\csname h\m \endcsname};
}

생성되는 출력이 아닌 매크로 자체를 저장하기 때문에 작동하지 않습니다.

누군가 출력을 변수 내에 저장하는 방법을 찾는 데 도움을 줄 수 있습니까?


내가 성취하려는 것에 대한 설명

1 최소 작업 예

\documentclass{standalone}
\usepackage{xargs,tikz}
\usetikzlibrary{decorations.markings,hobby}

\tikzset{
  mark pos/.style args={#1(#2)}{
    postaction={
      decorate,
      decoration={
        markings,
        mark=at position #1 with \coordinate (#2);
      }
    }
  }
}

\newcommandx*\arccal[6][6]{%
  \draw[#6,domain=#5] plot ({#1+#3*cos(\x)}, {#2+#4*sin(\x)});
}

\foreach \m in {1,...,9}{
  \expandafter\xdef\csname h\m \endcsname{mark pos=0.\m(m\m),}
}

\def\lkj{
  \foreach \m in {1,...,9}{\csname h\m \endcsname};
}

\begin{document}
\begin{tikzpicture}

\arccal{-2.8}{0}{0.6}{1.2}{270:90}[samples=50,ultra thick,
  mark pos=0.05(w1),
  mark pos=0.1(w2),
  mark pos=0.15(w3),
  mark pos=0.2(w4),
  mark pos=0.25(w5),
  mark pos=0.3(w6),
  mark pos=0.35(w7),
  mark pos=0.4(w8),
  mark pos=0.45(w9),
  mark pos=0.5(w10),
  mark pos=0.55(w11),
  mark pos=0.6(w12),
  mark pos=0.65(w13),
  mark pos=0.7(w14),
  mark pos=0.75(w15),
  mark pos=0.8(w16),
  mark pos=0.85(w17),
  mark pos=0.9(w18),
  mark pos=0.95(w19),
];
\draw[ultra thick] plot[smooth] coordinates {(w19)(w18)(w17)(w16)(w15)(w14)(w13)(w12)(w11)(w10)(w9)(w8)(w7)(w6)(w5)(w4)(w3)(w2)(w1)};

\end{tikzpicture}
\end{document}

2 해설

나는 "plot"으로 생성된 선을 통해 좌표를 배치하는 데 사용되는 "mark pos"라는 tikz 스타일을 가지고 있습니다.

다양한 패턴으로 부드럽게 관리/닫아야 하는 특정 반원형 모양을 만들기 위해 "플롯[부드러운]" 또는 "플롯[부드러운 순환]"을 사용하는 특정한 경우가 있습니다.

그런 다음 내가 원하는 특정 방식으로 이동하기 위해 일련의 좌표를 정의해야 합니다. 이 경우 원형/타원 형태를 형성하는 방정식을 사용하고 "mark pos"를 사용하여 좌표를 설정합니다.

어떤 경우에는 균질한 곡선을 형성하기 위해 상당한 양의 좌표를 정의해야 하므로 "foreach"를 사용하여 루프를 만들어 각 좌표를 수동으로 정의할 필요 없이 빠르게 만들고 싶었습니다.

foreach 매크로의 출력을 "\draw[x]" 안에 배치해야 하는데 원시 매크로 자체로는 이를 수행할 수 없습니다.


감사해요.


내가 Qrrbrbirlbel에 대해 언급한 예시

1 사례 1: Qrrbrbirlbel의 도움으로 지금 얻을 수 있는 것

\newcommandx*\arccalpath[6][6]{%
  \path[#6,domain=#5] plot ({#1+#3*cos(\x)}, {#2+#4*sin(\x)});
}

\arccalpath{-3}{0}{0.9}{1.2}{90:-90}[samples=50,ultra thick,
  mark positions={0.05}{z}];
\arccalpath{-2.8}{0}{0.6}{1.2}{270:90}[samples=50,ultra thick,
  mark positions={0.05}{w}]

\draw[ultra thick] plot[smooth,samples at={19,...,1}] (z\x);
\draw[ultra thick] plot[smooth,samples at={19,...,1}] (w\x);

생산물: 여기에 이미지 설명을 입력하세요

2 사례 2: 플롯 좌표에 모든 점(z1, z2, z3...)을 입력할 필요 없이 얻으려는 것입니다.

\newcommandx*\arccalpath[6][6]{%
  \path[#6,domain=#5] plot ({#1+#3*cos(\x)}, {#2+#4*sin(\x)});
}

\arccalpath{-3}{0}{0.9}{1.2}{90:-90}[samples=50,ultra thick,
  mark positions={0.05}{z}];
\arccalpath{-2.8}{0}{0.6}{1.2}{270:90}[samples=50,ultra thick,
  mark positions={0.05}{w}]

\draw[ultra thick] plot[smooth cycle,samples at={19,...,1}] coordinates
{(w19)(w18)(w17)(w16)(w15)(w14)(w13)(w12)(w11)(w10)(w9)(w8)(w7)(w6)(w5)(w4)(w3)(w2)(w1)(z19)(z18)(z17)(z16)(z15)(z14)(z13)(z12)(z11)(z10)(z9)(z8)(z7)(z6)(z5)(z4)(z3)(z2)(z1)};

생산물: 여기에 이미지 설명을 입력하세요

답변1

나는 이것에 다르게 접근 할 것입니다.

고정된 분리의 여러 표시는 구문 을 사용하여 배치할 수 있습니다 mark=between positions … and … step … with …. 설명서에 다 설명되어 있어요세부 사항. 키 값은 /pgf/decoration/mark info/sequence number증가하는 카운터를 제공합니다.


arccal또한 TikZ 형식의 중심과 반경이라는 두 가지 인수만 사용하는 TikZ 경로에서 사용할 수 있는 스타일을 제공하겠습니다 <x> and <y>.

세 번째 TikZ 그림은 타원형 호를 플롯 대신 타원형 호로 그립니다.

마지막 그림은 markings라이브러리를 사용하지 않고 단지 두 개의 호를 그립니다. 두 번째 그림은 다른 각도로 그려집니다. 호의 전체 길이 중 일부만큼 호를 줄여야 하는 경우 접근 방식은 좀 더 복잡하지만(총 길이는 PGF/TikZ의 장식 모듈에 의해서만 제공되며 쉽게 추출할 수 없습니다) 수십 개의 표시를 배치하고 이를 통해 선을 그리는 것보다 훨씬 낫습니다.


또한 있다더 좋은 방법중심 주위에 호를 그리는 것은 귀하의 질문과 관련이 없습니다.

암호

\documentclass{standalone}
\usepackage{xargs,tikz}
\usetikzlibrary{decorations.markings}
\tikzset{
  mark positions/.style 2 args={
    postaction=decorate,
    decoration={
      name=markings, % PGFMath isn't precise, cheat with 1-0.001
      mark=between positions #1 and 1-0.001 step #1 with \coordinate
           (#2\pgfkeysvalueof{/pgf/decoration/mark info/sequence number});}}}
\newcommandx*\arccal[6][6]{%
  \draw[#6,domain=#5] plot ({#1+#3*cos(\x)}, {#2+#4*sin(\x)});
}
\tikzset{arccal/.style n args=2{insert path={plot([shift={(#1)}]\x:#2)}}}
\begin{document}
\begin{tikzpicture}
\arccal{-2.8}{0}{0.6}{1.2}{270:90}[
  samples=50, ultra thick,
  mark positions={0.05}{w}
];
\draw[thick, green] plot[smooth, samples at={19, ..., 1}] (w\x);
\end{tikzpicture}

\begin{tikzpicture}
\draw[
  ultra thick, samples=50, domain=270:90,
  mark positions={0.05}{w}, arccal={-2.8, 0}{.6 and 1.2}];
\draw[thick, green] plot[smooth, samples at={19, ..., 1}] (w\x);
\end{tikzpicture}

\begin{tikzpicture}
\draw[ultra thick, shift={(-2.8, 0)}, mark positions={0.05}{w}]
  (270:.6 and 1.2) arc[start angle=270, end angle=90, x radius=.6, y radius=1.2];
\draw[thick, green] plot[smooth, samples at={19, ..., 1}] (w\x);
\end{tikzpicture}

\begin{tikzpicture}
\draw[ultra thick, shift={(-2.8, 0)}]
  (270:.6 and 1.2) arc[start angle=270, end angle= 90, x radius=.6, y radius=1.2];
\draw[thick, green, shift={(-2.8, 0)}]
  (255:.6 and 1.2) arc[start angle=255, end angle=105, x radius=.6, y radius=1.2];
\end{tikzpicture}
\end{document}

산출

여기에 이미지 설명을 입력하세요


내가 보기에 교차점 사이의 호를 결합하고 싶습니다.

다음은 세 가지 접근 방식입니다. 모두 intersections라이브러리를 사용하여 호/반타원을 구성하는 두 경로 사이의 교차점을 찾습니다.

첫 번째는 calc라이브러리의 let … in구문을 사용하여 다른 세트의 타원 중심에 대한 교차 각도를 계산합니다 arc. m1및 좌표 m2를 사용하여엑스변환을 직접 수행할 필요 없이 캔버스 좌표계에서 타원의 반경을 조정할 수 있습니다.

두 번째는 ext.paths.arcto내 라이브러리를 사용합니다.tikz-ext패키지호를 그릴 수 있게 해주는 것에게점, 각도는 PGF/TikZ에 의해 계산됩니다.

세 번째 솔루션은 spath3다른 경로와의 교차점에서 경로를 분할할 수 있는 라이브러리를 사용합니다. 분할된 경로의 어떤 구성요소를 그릴지 지정하기만 하면 됩니다.


솔루션 1과 2의 수학적 평가는 그다지 정확하지 않기 때문에 경로를 닫을 때 성가신 인공물이 발생할 수 있습니다.
여기에 이미지 설명을 입력하세요

spath3이는 의 키를 사용하여 수정 adjust and close하거나 를 사용하여 숨길 수 있습니다 line join=round.

전반적으로 나는 arc to접근 방식을 선호합니다.

  • calc접근 방식은 많은 수동 계산을 사용하지만 acos함수가 명확하지 않기 때문에(하나의 값에 대해 두 개의 각도) 조정이 필요하고
  • spath3솔루션에서는 호가 최대 4개의 베지어 곡선(각각 구성 요소에 해당)으로 구성되므로 까다로울 수 있는 구성 요소를 지정해야 합니다.

어느 쪽이든 아래 코드에는 모든 솔루션이 제시되어 있습니다. 나도 사용하고 있어요내 대답arc starts=after moveto중심 주위에 호를 더 쉽게 그릴 수 있도록 하기 위한 것 입니다 .

암호

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
%% https://tex.stackexchange.com/a/123189
\usepackage{etoolbox}
\makeatletter
\patchcmd{\tikz@arc@opt}{\xdef}{\tikz@arc@do\xdef}{}{}\let\tikz@arc@do\relax
\tikzset{arc starts/.cd,.is choice, at last point/.code=\let\tikz@arc@do\relax,after moveto/.code=\tikz@arc@do@\pgfpathmoveto,after lineto/.code=\tikz@arc@do@\pgfpathlineto}
\def\tikz@arc@do@#1{\def\tikz@arc@do{\tikz@@@parse@polar{\tikz@arc@do@@#1}(\tikz@s:\pgfkeysvalueof{/tikz/x radius} and \pgfkeysvalueof{/tikz/y radius})}}
\def\tikz@arc@do@@#1#2{#1{\pgfpointadd{#2}{\tikz@last@position@saved}}}
\makeatother

\usetikzlibrary{intersections} % solutions 1, 2, 3
\usetikzlibrary{
  calc,            % solution 1
  ext.paths.arcto, % solution 2
  spath3           % solutions (1, 2b,) 3
}
\tikzset{cycle/.style=/tikz/spath/adjust and close}
\begin{document}

%%% 1. calc (doing our own math)
\begin{tikzpicture}[
  arc starts=after moveto,
  e1/.style={x radius=.6, y radius=1.2},
  e2/.style={x radius=.9, y radius=1.2},
  label position=center, line join=round,
]
% the coordinate m1 and m2 are used to find the x radius in the canvas (w/ units)
\path[name path=e1] (-2.8, 0) coordinate (c1)
  arc[start angle=90, delta angle= 180, e1] coordinate[midway] (m1);
\path[name path=e2] (-3.0, 0) coordinate(c2)
  arc[start angle=90, delta angle=-180, e2] coordinate[midway] (m2);

\draw[
  ultra thick, arc starts=at last point,
  name intersections={of=e1 and e2}]
  % work in the coordinate system of the first ellipse:
  [shift=(c1), e1]
  let \p0=(intersection-1), \p1=(m1), \n0={180-acos(\x0/\x1)} in
   (intersection-1) arc[start angle=\n0, end angle=360-\n0]
  % work in the coordinate system of the second ellipse:
  [shift=(c2), e2]
  let \p0=(intersection-2), \p1=(m2), \n0={-acos(\x0/\x1)} in
   arc[start angle=\n0, end angle=-\n0]
   [cycle];
\end{tikzpicture}

%%% 2a. arc to + round line join
\begin{tikzpicture}[
  arc starts=after moveto, line join=round,
  e1/.style={x radius=.6, y radius=1.2},
  e2/.style={x radius=.9, y radius=1.2},
]
\path[name path=e1] (-2.8, 0) arc[start angle=90, delta angle= 180, e1];
\path[name path=e2] (-3.0, 0) arc[start angle=90, delta angle=-180, e2];

\draw[name intersections={of=e1 and e2}, ultra thick]
   (intersection-1) arc to[/tikz/e1] (intersection-2)
                    arc to[/tikz/e2] (intersection-1) -- cycle;
\end{tikzpicture}

%%% 2b. arc to + spath3
\begin{tikzpicture}[
  arc starts=after moveto,
  e1/.style={x radius=.6, y radius=1.2},
  e2/.style={x radius=.9, y radius=1.2},
]
\path[name path=e1] (-2.8, 0) arc[start angle=90, delta angle= 180, e1];
\path[name path=e2] (-3.0, 0) arc[start angle=90, delta angle=-180, e2];

\draw[name intersections={of=e1 and e2}, ultra thick]
   (intersection-1) arc to[/tikz/e1] (intersection-2)
                    arc to[/tikz/e2] (intersection-1) [cycle];
\end{tikzpicture}

% 3. spath
\begin{tikzpicture}[
  arc starts=after moveto,
  e1/.style={x radius=.6, y radius=1.2},
  e2/.style={x radius=.9, y radius=1.2},
  label position=center,
]
\path[name path=e1] (-2.8, 0) coordinate (c1)
  arc[start angle=90, delta angle= 180, e1];
\path[name path=e2] (-3.0, 0) coordinate(c2)
  arc[start angle=90, delta angle=-180, e2];

\draw[ultra thick, spath/.cd,
  split at intersections={e1}{e2},
  remove components={e1}{2,4},
  remove components={e2}{1,2,4},
  use=e1, append reverse=e2,
 ] -- cycle;
\end{tikzpicture}
\end{document}

산출

여기에 이미지 설명을 입력하세요

관련 정보