直角坐标系的旋转和平移

直角坐标系的旋转和平移

我需要绘制两个坐标系:第一个是主矩形,第二个位于第一个坐标系内,由沿第一个坐标系的每个轴的偏移量和围绕每个轴的三次旋转设置。假设旋转角度已知。

我发现了一个类似的例子,但是这里使用的是球面坐标,而我最初需要的是矩形:

% Author: Izaak Neutelings (June 2017)
% taken from https://tex.stackexchange.com/questions/159445/draw-in-cylindrical-and-spherical-coordinates
\documentclass[border=3pt,tikz]{standalone}
\usepackage{physics}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage[outline]{contour} % glow around text
\usepackage{xcolor}

\colorlet{veccol}{green!50!black}
\colorlet{projcol}{blue!70!black}
\colorlet{myblue}{blue!80!black}
\colorlet{myred}{red!90!black}
\colorlet{mydarkblue}{blue!50!black}
\tikzset{>=latex} % for LaTeX arrow head
\tikzstyle{proj}=[projcol!80,line width=0.08] %very thin
\tikzstyle{area}=[draw=veccol,fill=veccol!80,fill opacity=0.6]
\tikzstyle{vector}=[-stealth,myblue,thick,line cap=round]
\tikzstyle{unit vector}=[->,veccol,thick,line cap=round]
\tikzstyle{dark unit vector}=[unit vector,veccol!70!black]
\usetikzlibrary{angles,quotes} % for pic (angle labels)
\contourlength{1.3pt}

\begin{document}
    
    
    % 3D AXIS with spherical coordinates
    \tdplotsetmaincoords{60}{110} 
    %
    \pgfmathsetmacro{\rvec}{.8}
    \pgfmathsetmacro{\thetavec}{30}
    \pgfmathsetmacro{\phivec}{60}
    %
    \begin{tikzpicture}[scale=5,tdplot_main_coords]
        \coordinate (O) at (0,0,0);
        \draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$Z$};
        \draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$X$};

        \draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$Y$};
        \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
        \draw[-stealth,color=red] (O) -- (P);
        \draw[dashed, color=red] (O) -- (Pxy);
        \draw[dashed, color=red] (P) -- (Pxy);
        \tdplotdrawarc{(O)}{0.2}{0}{\phivec}{anchor=north}{$\phi$}
        \tdplotsetthetaplanecoords{\phivec}
        \tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{0.5}{0}%
        {\thetavec}{anchor=south west}{$\theta$}
        \draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec);
        \draw[dashed] (\rvec,0,0) arc (0:90:\rvec);
        \tdplotsetrotatedcoords{\phivec}{\thetavec}{0}
        \tdplotsetrotatedcoordsorigin{(P)}
        \draw[thick,tdplot_rotated_coords,->] (0,0,0)
        -- (.5,0,0) node[anchor=north west]{$Z’$};
        \draw[thick,tdplot_rotated_coords,->] (0,0,0)
        -- (0,.5,0) node[anchor=west]{$X’$};
        \draw[thick,tdplot_rotated_coords,->] (0,0,0)
        -- (0,0,.5) node[anchor=south]{$Y’$};
        \draw[-stealth,color=blue,tdplot_rotated_coords] (0,0,0) -- (.2,.2,.2);
        \draw[dashed,color=blue,tdplot_rotated_coords] (0,0,0) -- (.2,.2,0);
        \draw[dashed,color=blue,tdplot_rotated_coords] (.2,.2,0) -- (.2,.2,.2);
        \tdplotdrawarc[tdplot_rotated_coords,color=blue]{(0,0,0)}{0.2}{0}%
        {45}{anchor=north west,color=black}{$\phi’$}
        \tdplotsetrotatedthetaplanecoords{45}
        \tdplotdrawarc[tdplot_rotated_coords,color=blue]{(0,0,0)}{0.2}{0}%
        {55}{anchor=south west,color=black}{$\theta’$}
    \end{tikzpicture}

\end{document}

在此处输入图片描述

我还找到了一个类似的坐标旋转示例。但我做不对: 通过平移和旋转从一个笛卡尔三维坐标系转换为另一个

答案1

如果只是平面上的旋转和平移,最简单的解决方案是使用范围

\documentclass{article}
\usepackage{tikz}
\usepackage{esvect}
\begin{document}
\begin{tikzpicture}
\draw[-latex] (0,0,0) coordinate(O) node[left]{$O_0$}-- ++ (10,0,0) node[above]{$\vv{x_0}$};
\draw[-latex] (O) -- ++ (0,10,0) node[right]{$\vv{y_0}$};

\draw[-latex] (O) -- ++ (0,0,10,0) node[above]{$\vv{z_0}$};
\draw[blue]  (1,2,0) node[above]{$A_0$} -- (-2,4,0) node[above]{$B_0$};

\begin{scope}[shift={(4,3,0)}, rotate=15]
\draw[-latex,red] (0,0,0) coordinate(O1) node[left]{$O_1$}-- ++ (7,0,0) node[above]{$\vv{x_1}$};

\draw[-latex,red] (O1) -- ++ (0,7,0) node[right]{$\vv{y_1}$};
\draw[-latex,red] (O1) -- ++ (0,0,7,0) node[above]{$\vv{z_1}$};
\draw[blue]  (1,2,0) node[above]{$A_1$} -- (-2,4,0) node[above]{$B_1$};
\end{scope}

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容