为什么 tikz 中的这种旋转不起作用?

为什么 tikz 中的这种旋转不起作用?
    \begin{tikzpicture}
\node [draw=black, anchor=south west] (label) at (0,0){\includegraphics[width=300mm]{th.jpg}};
\coordinate (ZX) at (157mm,104mm);
\coordinate (YB) at (249mm,39mm);
\coordinate (YY) at ($(ZX)!1.5!(YB)$);
\coordinate (ZZ) at ($(YB)!2.5!(ZX)$);
\draw[blue!20,very thick] (ZZ)--(YY);
\draw[red!20,very thick, rotate around={90:(ZX)}] (157mm,104mm)--(249mm,39mm);%It works
\draw[red!20,very thick, rotate around={-90:(ZX)}] (ZX)--(YB);%It doesn't work
\filldraw[white] (ZX) circle (2mm);
\filldraw[white] (YB) circle (2mm);
\end{tikzpicture}

一个工作示例

     \documentclass{minimal}
\usepackage{tikz,tikz-3dplot}

\begin{document}

  \tdplotsetmaincoords{70}{115}

  \begin{tikzpicture}[scale=4,tdplot_main_coords]
\pgfmathsetmacro{\rvec}{.8}
\pgfmathsetmacro{\thetavec}{30}
\pgfmathsetmacro{\phivec}{60}

\tdplotsetrotatedcoords{\phivec}{\thetavec}{0}

 \coordinate (O) at (1,1,1);

 %these 2 lines overlap
\draw[thick,->] (O) -- (0,.5,0);
\draw[thick,tdplot_rotated_coords,->] (O) -- (0,.5,0);

 %these 2 lines dont overlap
\draw[thick,->] (1,1,1) -- (0,.5,0);
\draw[thick,tdplot_rotated_coords,->] (1,1,1) -- (0,.5,0);
\end{tikzpicture}
\end{document}

答案1

在 TikZ/pgf 中,变换仅适用于数字坐标。您可以检索原始数字坐标(仅限 2D)通过操作从节点或坐标let

\draw[red,very thick] let \p1=(ZX),\p2=(YB) in
[rotate around={-90:(ZX)}] (\p1)--(\p2);

完整示例:

在此处输入图片描述

\documentclass[tikz]{standalone}
\usetikzlibrary{calc} 
\begin{document}
\begin{tikzpicture}
  \node [draw=black, anchor=south west] (label) at (0,0){\includegraphics[width=300mm]{example-image}};
  \coordinate (ZX) at (157mm,104mm);
  \coordinate (YB) at (249mm,39mm);
  \coordinate (YY) at ($(ZX)!1.5!(YB)$);
  \coordinate (ZZ) at ($(YB)!2.5!(ZX)$);
  \draw[blue!20,very thick] (ZZ)--(YY);
  \draw[red!20,very thick, rotate around={90:(ZX)}]
  (157mm,104mm)--(249mm,39mm);%It works

  \draw[red,very thick] let \p1=(ZX),\p2=(YB) in
  [rotate around={-90:(ZX)}] (\p1)--(\p2);
  \filldraw[white] (ZX) circle (2mm);
  \filldraw[white] (YB) circle (2mm);
\end{tikzpicture}
\end{document}

笔记:此方法不能用于 3D 坐标和 3D 变换,因为nodecoordinate存储的是 2D 投影。

相关内容