在Tikz中围绕坐标原点旋转

在Tikz中围绕坐标原点旋转

我用旋转命令可以围绕原点旋转图形。但是,当我用参考代替坐标时,此方法不起作用。

\documentclass[a4paper,12pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections,through,backgrounds}

\begin{document}

\begin{tikzpicture}[scale = 0.05]
% frame
\coordinate (O) at (0,0);   \coordinate (H) at (120:50);
\coordinate (S) at (-50,0); \coordinate (D) at (30,0);
\coordinate (D1) at (30,-15); \coordinate (D2) at (30,15);

\begin{scope}[rotate=60]
    \filldraw[fill=red] (S) circle [radius=0.5];    % source
    \foreach \y in {-10,...,9}
    {
        \draw (D) ++(0,\y*1.5) rectangle +(1.5,1.5);
    }
    \begin{pgfonlayer}{background}
        \fill[green!20] (S) -- (D1) -- (D2) -- cycle; %projection
    \end{pgfonlayer}
\end{scope}

\node [very thin,draw=blue!80!black,label=above left:orbit,circle through=(H)] (Or) at (O) {};

\end{tikzpicture}
\end{document}

在此处输入图片描述

当我删除参考并直接使用坐标时,Tikz 表现良好。

\documentclass[a4paper,12pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections,through,backgrounds}

\begin{document}


\begin{tikzpicture}[scale = 0.05]
\coordinate (X-) at (-60,0); \coordinate [label=right:$x$] (X+) at (60,0);
\coordinate (Y-) at (0,-60); \coordinate [label=left:$y$] (Y+) at (0,60);
\coordinate (O) at (0,0);   \coordinate (H) at (120:50);
\draw[->,help lines] (X-) -- (X+);
\draw[->,help lines] (Y-) -- (Y+);
\begin{scope}[rotate=60]
    \filldraw[fill=red] (-50,0) circle [radius=0.5];    % source
    \foreach \y in {-10,...,9}
    {
        \draw (30,0) ++(0,\y*1.5) rectangle +(1.5,1.5);
    }
    \begin{pgfonlayer}{background}
        \fill[green!20] (-50,0) -- (30,-15) -- (30,15) -- cycle; %projection
    \end{pgfonlayer}
\end{scope}

\node [very thin,draw=blue!80!black,label=above left:orbit,circle through=(H)] (Or) at (O) {};

\end{tikzpicture}

\end{document}

在此处输入图片描述

那么我的第一个代码有什么问题?

答案1

正如 Harish Kumar 所说,这应该会产生所需的输出:

\documentclass[a4paper,12pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections,through,backgrounds}

\begin{document}

\begin{tikzpicture}[scale = 0.05]
% frame

\begin{scope}[rotate=60]
    \coordinate (O) at (0,0);   
    \coordinate (H) at (120:50);
    \coordinate (D) at (30,0);
    \coordinate (S) at (-50,0); 
    \coordinate (D1) at (30,-15); 
    \coordinate (D2) at (30,15);


    \filldraw[fill=red] (S) circle [radius=0.5];    % source
    \foreach \y in {-10,...,9}
    {
        \draw (D) ++(0,\y*1.5) rectangle +(1.5,1.5);
    }
\end{scope}

    \begin{pgfonlayer}{background}
        \fill[green!20] (S) -- (D1) -- (D2) -- cycle; %projection
    \end{pgfonlayer}

%\node [very thin,draw=blue!80!black,label=above left:orbit,circle through=(H)] (Or) at (O) {};
\node [very thin,draw=blue!80!black,label={[rotate=60]above left:orbit},circle through=(H)] (Or) at (O) {};

\end{tikzpicture}
\end{document}

或者你可以旋转 cancas:

\begin{pgfonlayer}{background}
        \pgflowlevel{\pgftransformrotate{60}}  
        \fill[green!20] (S) -- (D1) -- (D2) -- cycle; %projection
\end{pgfonlayer}

在此处输入图片描述

相关内容