
저는 사용이 처음이지만 \foreach
일반적으로 코딩하지는 않습니다. 이 예의 답변 번호 40에 있는 코드를 따르세요.TikZ의 경로에서 임의 점의 접선을 그리는 방법
tangent=0.x
draw 문에서 목록을 어떻게 적절하게 압축할 수 있나요 ?
나는 성공하지 못한 몇 가지 아이디어를 시도했습니다.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
tangent/.style={
decoration={
markings,% switch on markings
mark=
at position #1
with
{
\coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
\coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
\coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
}
},
postaction=decorate
},
use tangent/.style={
shift=(tangent point-#1),
x=(tangent unit vector-#1),
y=(tangent orthogonal unit vector-#1)
},
use tangent/.default=1
]
\draw [
tangent=0.1,
tangent=0.2,
tangent=0.3,
tangent=0.4,
tangent=0.5,
tangent=0.6,
tangent=0.7,
tangent=0.8,
tangent=0.9,
%%%% attempt 1
%tangent={0.05,0.01,...0.95}
%%%%% attempt 2
%\foreach \y in {0.1,0.2,...,0.9}
%{
%tangent=\y,
%}
] (0,0) arc (180:0:10);
\foreach \x [count=\xi] in {1,1,2,1,2,1,4,3,1.5}
{
\draw [red, thick,->, use tangent=\xi] (0,0) -- (0,-1*\x);
}
\end{tikzpicture}
\end{document}
다음과 같은 결과를 얻으려면 :
draw 문에서 tangent=0.x 목록을 올바르게 압축하려면 어떻게 해야 합니까?
답변1
동일한 키를 반복적으로 호출해야 하는 경우 를 사용할 수 있습니다. <key>/.list={<foreach expression>}
여기서는 <foreach expression>
간단한 목록이거나 타원이 있는 목록일 수 있습니다. 따라서 이 경우에는 다음을 사용할 수 있습니다.\draw [tangent/.list={0.1,0.2,...,0.9}](0,0) arc (180:0:10);
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
tangent/.style={
decoration={
markings,% switch on markings
mark=
at position #1
with
{
\coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
\coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
\coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
}
},
postaction=decorate
},
use tangent/.style={
shift=(tangent point-#1),
x=(tangent unit vector-#1),
y=(tangent orthogonal unit vector-#1)
},
use tangent/.default=1
]
\draw [tangent/.list={0.1,0.2,...,0.9}](0,0) arc (180:0:10);
\foreach \x [count=\xi] in {1,1,2,1,2,1,4,3,1.5}
{
\draw [red, thick,->, use tangent=\xi] (0,0) -- (0,-1*\x);
}
\end{tikzpicture}
\end{document}
답변2
이것은 약간 다른 접근 방식이지만(해결 방법임을 인정합니다) 이 시나리오에서는 잘 작동합니다.
\foreach [count=\y] \x in {1,1,2,1,2,1,4,3,1.5}
{
\path [tangent=\y/10] (0,0) arc (180:0:10);
\draw [red, thick, ->, use tangent=1] (0,0) -- (0,-1*\x);
}
\draw (0,0) arc (180:0:10);
tikzpicture
이 코드로 본문을 교체하면 됩니다 .
최종 코드:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
tangent/.style={
decoration={
markings,% switch on markings
mark=
at position #1
with
{
\coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
\coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
\coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
}
},
postaction=decorate
},
use tangent/.style={
shift=(tangent point-#1),
x=(tangent unit vector-#1),
y=(tangent orthogonal unit vector-#1)
},
use tangent/.default=1
]
\foreach [count=\y] \x in {1,1,2,1,2,1,4,3,1.5}
{
\path [tangent=\y/10] (0,0) arc (180:0:10);
\draw [red, thick,->, use tangent=1] (0,0) -- (0,-1*\x);
}
\draw (0,0) arc (180:0:10);
\end{tikzpicture}
\end{document}
답변3
이는 를 사용하여 쉽게 수행할 수 있습니다 foreach
. 나는 당신보다 더 간단한 접근 방식을 사용합니다. 결과는
\documentclass[border={10}]{standalone}
\usepackage{tikz}
\begin{document}
\def \r {8}
\begin{tikzpicture}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw[very thick] (\r,0) arc (0:180:\r);
\foreach \angle / \y in {18/6, 36/7, 54/6, 72/7,90/6, 108/7,126/6,144/7,162/6}
\draw [<-, very thick,red]
( { (\y)*cos(\angle)}, { (\y)*sin(\angle)} ) --
( { (\r)*cos(\angle)}, { (\r)*sin(\angle)} );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{tikzpicture}
\end{document}