我有一个pic
包括一艘航天器和一个附在它上面的本地框架,如下所示。
pics/spacecraft/.style n args={2}{
code={
\node [shape=rectangle, draw, fill=gray!30, inner sep=0pt, minimum width=0.9em, minimum height=0.9em] () {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, xshift=2mm, rotate around={90:(0,0)}] {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, yshift=2mm, rotate around={180:(0,0)}] {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, yshift=-2mm, rotate around={0:(0,0)}] {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, xshift=-2mm, rotate around={270:(0,0)}] {};
\draw (0,0) circle (0.7mm);
\draw[fill=black] (0,0) -- (0:0.7mm) arc(0:90:0.7mm) -- cycle;
\draw[fill=black] (0,0) -- (180:0.7mm) arc(180:270:0.7mm) -- cycle;
\draw[-latex, very thin] (0,0) -- (0,9mm) node[pos=0.9,above] {$\Scale[#2]{y_{#1}}$};
\draw[-latex, very thin, label=right:2mm] (0,0) -- (9mm,0) node[pos=0.9,right] {$\Scale[#2]{x_{#1}}$};
}
}
我想使用 旋转整张图片(除其标签外)[rotate = <some degree>]
。但当前代码仅旋转框架而不旋转航天器。
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{positioning,automata,,shapes.geometric,arrows.meta}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
\tikzset{
pics/spacecraft/.style n args={2}{
code={
\node [shape=rectangle, draw, fill=gray!30, inner sep=0pt, minimum width=0.9em, minimum height=0.9em] () {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, xshift=2mm, rotate around={90:(0,0)}] {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, yshift=2mm, rotate around={180:(0,0)}] {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, yshift=-2mm, rotate around={0:(0,0)}] {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, xshift=-2mm, rotate around={270:(0,0)}] {};
\draw (0,0) circle (0.7mm);
\draw[fill=black] (0,0) -- (0:0.7mm) arc(0:90:0.7mm) -- cycle;
\draw[fill=black] (0,0) -- (180:0.7mm) arc(180:270:0.7mm) -- cycle;
\draw[-latex, very thin] (0,0) -- (0,9mm) node[pos=0.9,above] {$\Scale[#2]{y_{#1}}$};
\draw[-latex, very thin, label=right:2mm] (0,0) -- (9mm,0) node[pos=0.9,right] {$\Scale[#2]{x_{#1}}$};
}
}
}
\begin{document}
\begin{tikzpicture}
\pic[rotate=120] (scB) at (3.5,1.5) {spacecraft={1}{0.5}};
\end{tikzpicture}
\end{document}
我在这里做错了什么?
答案1
transform shape
仅当设置了该选项时,节点才会转换:
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{positioning,automata,shapes.geometric,arrows.meta}
\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
\tikzset{
pics/spacecraft/.style n args={2}{
code={
\begin{scope}[
every node/.style = {
transform shape
}
]
\node [shape=rectangle, draw, fill=gray!30, inner sep=0pt, minimum width=0.9em, minimum height=0.9em] () {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, xshift=2mm, rotate around={90:(0,0)}] {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, yshift=2mm, rotate around={180:(0,0)}] {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, yshift=-2mm, rotate around={0:(0,0)}] {};
\node [trapezium, fill=gray!30, trapezium angle=60, inner sep = 1pt, minimum width=1mm, draw, xshift=-2mm, rotate around={270:(0,0)}] {};
\end{scope}
\draw (0,0) circle (0.7mm);
\draw[fill=black] (0,0) -- (0:0.7mm) arc(0:90:0.7mm) -- cycle;
\draw[fill=black] (0,0) -- (180:0.7mm) arc(180:270:0.7mm) -- cycle;
\draw[-latex, very thin] (0,0) -- (0,9mm) node[pos=0.9,above] {$\Scale[#2]{y_{#1}}$};
\draw[-latex, very thin, label=right:2mm] (0,0) -- (9mm,0) node[pos=0.9,right] {$\Scale[#2]{x_{#1}}$};
}
}
}
\begin{document}
\begin{tikzpicture}
\pic[rotate=120] (scB) at (3.5,1.5) {spacecraft={1}{0.5}};
\end{tikzpicture}
\end{document}