旋转后确定坐标位置?

旋转后确定坐标位置?

我设法将一些定义为图片的立方体定位在一个平面上,现在我想确定每个盒子中下框的位置,以便可以绘制从原点到此位置的矢量。但该命令rotate around z=...似乎改变了已知的矢量终点位置(=盒子中的下框)。

如果盒子没有旋转并且没有添加任何内容(盒子内的框架偏移),则位置是正确的(除了盒子内框架的偏移),但我如何设法跟随这个位置​​,即使在旋转之后也添加框架偏移(M在我的盒子图中表示)。

笔记:即使是黄色框箭头也只指向框而不是里面的下框。因此在所有情况下都需要向量加法。(至少我是这么认为的。但无论出于什么原因,这也没有指向正确的位置。) 目标:不要指向盒子角落,而是指向框架内部,即使旋转之后也是如此。 在此处输入图片描述 在此处输入图片描述 在此处输入图片描述

\documentclass[tikz,border=1cm]{standalone}
\usetikzlibrary{backgrounds,perspective,calc} 

\begin{document}
\begin{tikzpicture}[>=latex,line cap=round,line join=round,scale=2]
\newcommand{\simpleaxes}[6]{% 1-3 position, 4-6 size
\draw[->] (-0.5+#1,#2,#3) -- (#1+#4,#2,#3) node[pos=1.1]{x};
\draw[->] (#1,-0.5+#2,#3) -- (#1,#2+#5,#3) node[pos=1.1]{y};
\draw[->] (#1,#2,-0.5+#3) -- (#1,#2,#3+#6) node[pos=1.1]{z};}
\tikzset{pics/coordsys/.style={
    code = {\tikzset{coordsys/.cd,#1}
        \draw [->,pic actions] (0,0,0) -- (1,0,0)[red] node[pos=1.4]
          {$\pgfkeysvalueof{/tikz/coordsys/x}$};
        \draw [->,pic actions] (0,0,0) -- (0,1,0)[green!60!black] node[pos=1.2]
          {$\pgfkeysvalueof{/tikz/coordsys/y}$};
        \draw [->,pic actions] (0,0,0) -- (0,0,1)[blue] node[pos=1.2]
          {$\pgfkeysvalueof{/tikz/coordsys/z}$};
    }
},coordsys/.cd,x/.initial=x,y/.initial=y,z/.initial=z} 

\tikzset{pics/coordsysshift/.style={
    code = {\tikzset{coordsysshift/.cd,#1}
      \begin{scope}[rotate around z=45, rotate around y=45, rotate around x=45]
        \draw [->,pic actions] (0,0,0) -- (1,0,0)[red] node[pos=1.3]
          {$\pgfkeysvalueof{/tikz/coordsysshift/x}$};
        \draw [->,pic actions] (0,0,0) -- (0,1,0)[green!60!black] node[pos=1.2]
          {$\pgfkeysvalueof{/tikz/coordsysshift/y}$};
        \draw [->,pic actions] (0,0,0) -- (0,0,1)[blue] node[pos=1.2]
          {$\pgfkeysvalueof{/tikz/coordsysshift/z}$};
      \end{scope}
    }
},coordsysshift/.cd,x/.initial=x,y/.initial=y,z/.initial=z} 


\tikzset{
  pics/complicated/.style={
    code={
      \tikzset{complicated/.cd,#1}
      \begin{scope}[transparency group, fill opacity=0.8]
          \draw[\boxframecolor,fill=\boxfillcolor] (0,0,\cubez) %xy plane/top face
           -- ++(\cubex,0,0)
            -- ++(0,\cubey,0)
             -- ++(-\cubex,0,0) -- cycle;
          \draw[\boxframecolor,fill=\boxfillcolor] (0,0,0) %yz plane/left face
           -- ++(0,0,\cubez)
            -- ++(0,\cubey,0)
             -- ++(0,0,-\cubez) -- cycle;
          \draw[\boxframecolor,fill=\boxfillcolor] (0,0,0) %xz plane/front face
           -- ++(\cubex,0,0)
            -- ++(0,0,\cubez)
             -- ++(-\cubex,0,0) -- cycle;

        %%%% define positioning of M,B frames inside box
        \pgfmathsetmacro{\dx}{0.5};
        \pgfmathsetmacro{\dy}{0.5};
        \pgfmathsetmacro{\dz}{0.4};
        \coordinate (origin) at (-5,0,0);
        %\coordinate (M) at (\dx,\cubey-\dy,\dz);
        %\coordinate (B) at (\cubex-\dx,\dy,\cubez-\dz);
        \coordinate (M) at (\dx,\dy,\dz);
        \coordinate (B) at (\cubex-\dx,\cubey-\dy,\cubez-\dz);

        \draw (M) pic[thick] {coordsys={x=x_M,y=y_M,z=z_M}};
        \node [below right] at (M.south) {\textit{M}};
        \draw (B) pic[dotted] {coordsys={x=x_M',y=y_M',z=z_M'}};
        \node [above left] at (B.west) {\textit{B}};
        \draw (B) pic[thick] {coordsysshift={x=x_{B},y=y_{B},z=z_{B}}};

        \draw [->, thick] (M) -- (B) node [midway,fill=\boxfillcolor] {$q_{MB}, r_{MB}$};
      \end{scope}
    }
  },
  complicated/.cd,
    cube x/.store in=\cubex,
    cube x=8,
    cube y/.store in=\cubey,
    cube y=8,
    cube z/.store in=\cubez,
    cube z=2,
    box fill color/.store in=\boxfillcolor,
    box fill color=yellow!25,
    box frame color/.store in=\boxframecolor,
    box frame color=gray!25
}



\begin{scope}[3d view={-80}{15}]
  \simpleaxes{0}{0}{0}{8}{8}{2};

  \coordinate (posyellow) at (0,5,0);
  \coordinate (posblue) at (2,4,0);
  \path (0,5,0) pic(yellow) {complicated={box frame color=yellow}};

  % in line below: [rotate around z=-50] is the problem, how to follow rot. ?
  \path [rotate around z=-50](2,4,0) pic (blue) {complicated={box fill color=blue!25,box frame color=blue}};
  \path (0,0,-5) pic {coordsys};

  \draw [->,dotted, opacity=0.8] (0,0,-5) -- ($(posyellow)$); % +yellowM
  \draw [->,dotted, opacity=0.8] (0,0,-5) -- ($(posblue)$);%,rotate around z=-50 % ($(posblue)+(blueM)$)

\end{scope}

\end{tikzpicture}
\end{document}

答案1

您只需(origin)在 的原点添加一个命名坐标即可pic。鉴于pic具有名称yellow和,该坐标可以从外部blue称为yelloworigin和。blueorigin

\documentclass[tikz,border=1cm]{standalone}
\usetikzlibrary{backgrounds,perspective,calc} 

\begin{document}
\begin{tikzpicture}[>=latex,line cap=round,line join=round,scale=2]
\newcommand{\simpleaxes}[6]{% 1-3 position, 4-6 size
\draw[->] (-0.5+#1,#2,#3) -- (#1+#4,#2,#3) node[pos=1.1]{x};
\draw[->] (#1,-0.5+#2,#3) -- (#1,#2+#5,#3) node[pos=1.1]{y};
\draw[->] (#1,#2,-0.5+#3) -- (#1,#2,#3+#6) node[pos=1.1]{z};}
\tikzset{pics/coordsys/.style={
    code = {\tikzset{coordsys/.cd,#1}
        \draw [->,pic actions] (0,0,0) -- (1,0,0)[red] node[pos=1.4]
          {$\pgfkeysvalueof{/tikz/coordsys/x}$};
        \draw [->,pic actions] (0,0,0) -- (0,1,0)[green!60!black] node[pos=1.2]
          {$\pgfkeysvalueof{/tikz/coordsys/y}$};
        \draw [->,pic actions] (0,0,0) -- (0,0,1)[blue] node[pos=1.2]
          {$\pgfkeysvalueof{/tikz/coordsys/z}$};
    }
},coordsys/.cd,x/.initial=x,y/.initial=y,z/.initial=z} 

\tikzset{pics/coordsysshift/.style={
    code = {\tikzset{coordsysshift/.cd,#1}
      \begin{scope}[rotate around z=45, rotate around y=45, rotate around x=45]
        \draw [->,pic actions] (0,0,0) -- (1,0,0)[red] node[pos=1.3]
          {$\pgfkeysvalueof{/tikz/coordsysshift/x}$};
        \draw [->,pic actions] (0,0,0) -- (0,1,0)[green!60!black] node[pos=1.2]
          {$\pgfkeysvalueof{/tikz/coordsysshift/y}$};
        \draw [->,pic actions] (0,0,0) -- (0,0,1)[blue] node[pos=1.2]
          {$\pgfkeysvalueof{/tikz/coordsysshift/z}$};
      \end{scope}
    }
},coordsysshift/.cd,x/.initial=x,y/.initial=y,z/.initial=z} 


\tikzset{
  pics/complicated/.style={
    code={
      \tikzset{complicated/.cd,#1}
      \begin{scope}[transparency group, fill opacity=0.8]
          \draw[\boxframecolor,fill=\boxfillcolor] (0,0,\cubez) %xy plane/top face
           -- ++(\cubex,0,0)
            -- ++(0,\cubey,0)
             -- ++(-\cubex,0,0) -- cycle;
          \draw[\boxframecolor,fill=\boxfillcolor] (0,0,0) %yz plane/left face
           -- ++(0,0,\cubez)
            -- ++(0,\cubey,0)
             -- ++(0,0,-\cubez) -- cycle;
          \draw[\boxframecolor,fill=\boxfillcolor] (0,0,0) %xz plane/front face
           -- ++(\cubex,0,0)
            -- ++(0,0,\cubez)
             -- ++(-\cubex,0,0) -- cycle;

        %%%% define positioning of M,B frames inside box
        \pgfmathsetmacro{\dx}{0.5};
        \pgfmathsetmacro{\dy}{0.5};
        \pgfmathsetmacro{\dz}{0.4};
        \coordinate (origin) at (-5,0,0);
        %\coordinate (M) at (\dx,\cubey-\dy,\dz);
        %\coordinate (B) at (\cubex-\dx,\dy,\cubez-\dz);
        \coordinate (M) at (\dx,\dy,\dz);
        \coordinate (B) at (\cubex-\dx,\cubey-\dy,\cubez-\dz);
        \path (0,0,0) coordinate (origin);
        \draw (M) pic[thick] {coordsys={x=x_M,y=y_M,z=z_M}};
        \node [below right] at (M.south) {\textit{M}};
        \draw (B) pic[dotted] {coordsys={x=x_M',y=y_M',z=z_M'}};
        \node [above left] at (B.west) {\textit{B}};
        \draw (B) pic[thick] {coordsysshift={x=x_{B},y=y_{B},z=z_{B}}};

        \draw [->, thick] (M) -- (B) node [midway,fill=\boxfillcolor] {$q_{MB}, r_{MB}$};
      \end{scope}
    }
  },
  complicated/.cd,
    cube x/.store in=\cubex,
    cube x=8,
    cube y/.store in=\cubey,
    cube y=8,
    cube z/.store in=\cubez,
    cube z=2,
    box fill color/.store in=\boxfillcolor,
    box fill color=yellow!25,
    box frame color/.store in=\boxframecolor,
    box frame color=gray!25
}



\begin{scope}[3d view={-80}{15}]
  \simpleaxes{0}{0}{0}{8}{8}{2};

  \coordinate (posyellow) at (0,5,0);
  \coordinate (posblue) at (2,4,0);
  \path (0,5,0) pic(yellow) {complicated={box frame color=yellow}};

  % in line below: [rotate around z=-50] is the problem, how to follow rot. ?
  \path [rotate around z=-50](2,4,0) pic (blue) {complicated={box fill color=blue!25,box frame color=blue}};
  \path (0,0,-5) pic {coordsys};

  \draw [->,dotted, opacity=0.8] (0,0,-5) -- (yelloworigin); % +yellowM
  \draw [->,dotted, opacity=0.8] (0,0,-5) -- (blueorigin);%,rotate around z=-50 % ($(posblue)+(blueM)$)

\end{scope}

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容