如何在 Tikz 中创建一致的 3D 图像

如何在 Tikz 中创建一致的 3D 图像

我想创建类似于这些的图像:在此处输入图片描述 在此处输入图片描述

但是我希望能够以特定于坐标系的方式做到这一点,这样我就不必考虑图像的二维投影与它应该表示的三维图像之间的关系。例如:在第二幅图像中,有没有办法指定一个以特定 z 坐标为中心的给定半径的圆,这样当从不同角度观看时,圆会发生变化(变成椭圆),从而实现透视效果?

基本上,我想在 3D 中定义对象并让 tikz 完成与旋转等有关的所有工作。

答案1

这是一个尝试。在第一个图上,第一象限与第二个图相同,但 x 轴和 y 轴标记互换,然后在负方向上绘制 x 轴线。有关命令的详细用法,可以在文档中找到tikz-3dplot

在此处输入图片描述

代码

\documentclass[border=10pt,varwidth]{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}
% ----- First plot    
\tdplotsetmaincoords{70}{145}
\begin{tikzpicture} [scale=3, tdplot_main_coords, axis/.style={->,blue,thick},
vector/.style={-stealth,black,very thick},
vector guide/.style={dotted,black,thick},
]

%standard tikz coordinate definition using x, y, z coords
\coordinate (O) at (0,0,0);

%tikz-3dplot coordinate definition using r, theta, phi coords
\pgfmathsetmacro{\ax}{1}
\pgfmathsetmacro{\ay}{-1}
\pgfmathsetmacro{\az}{0.5}

\coordinate (P) at (\ax,\ay,\az){};

%draw axes
    \draw[axis] (0,0,0) -- (2,0,0) node[anchor=north east]{$y$};   % x-axis becomes y axis
    \draw[axis] (0,0,0) -- (0,-2,0) node[anchor=south]{$x$}; %minius y-axis becomes positive x axis
    \draw[axis] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};

%draw a vector from O to P
\draw[vector guide] (O) -- (P)node{$\bullet$} node[left](){$(x,y,z)$};

% draw guide lines to components
\draw[vector guide] (O) -- (\ax,\ay,0);
\draw[vector guide] (\ax,\ay,0) -- (P);
\draw[vector guide] (\ax,\ay,0) -- (0,\ay,0);
\draw[vector guide] (\ax,\ay,0) -- (0,\ay,0);
\draw[vector guide] (\ax,\ay,0) -- (\ax,0,0);
\node[tdplot_main_coords,anchor=east]  at (\ax,0,0){};
\node[tdplot_main_coords,anchor=west]  at (0,\ay,0){};

\draw[thick,tdplot_main_coords] (1.5,0.5,0)-- (1.5,-0.5,0) -- (-1.5,-0.5,0)--(-1.5,0.5,0)--cycle;
\node[above] at (-0.6,0.1,0){$\bullet$};
\node at (-1,0,0) {$(x_0,y_0)$};

\draw[tdplot_main_coords,->,>=latex'] (0,2,0)--node[midway,above]{$U$} (0,1,0);
\end{tikzpicture}

% Second plot

\tdplotsetmaincoords{70}{115}
\begin{tikzpicture} [scale=3, tdplot_main_coords, axis/.style={->,blue,thick},
vector/.style={-stealth,black,very thick},
vector guide/.style={dashed,black,thick}]

%standard tikz coordinate definition using x, y, z coords
\coordinate (O) at (0,0,0);

%tikz-3dplot coordinate definition using r, theta, phi coords

\pgfmathsetmacro{\ax}{1}
\pgfmathsetmacro{\ay}{1}
\pgfmathsetmacro{\az}{1}

\coordinate (P) at (\ax,\ay,\az){};

%draw axes
    \draw[axis] (0,0,0) -- (2,0,0) node[anchor=north east]{$\mathbf{e_x}$};
    \draw[axis] (0,0,0) -- (0,2,0) node[anchor=north west]{$\mathbf{e_y}$};
    \draw[axis] (0,0,0) -- (0,0,2) node[anchor=south]{$\mathbf{e_z}$};

%draw a vector from O to P
\draw[vector] (O) -- (P);% node(){$\bullet$};

\tdplotdrawarc[tdplot_main_coords]{(0,0,1)}{1.414}{0}{360}{anchor=north}{}

% draw guide lines to components
\draw[vector guide] (O) -- (\ax,\ay,0);
\draw[vector guide] (\ax,\ay,0) -- (P);
\draw[thick, <-,>=latex']  (P) --node[midway,above]{$r'$} (0,0,\az);
\node[tdplot_main_coords,above,left] at (0,-0.2,\az){$\zeta_3$};

\draw[thick,tdplot_main_coords,->,>=latex'] (1,1,1)-- (1,1,0.5) node[anchor=west]{$F_T$};
\draw[thick,tdplot_main_coords,->,>=latex'] (1,1,1)-- (1.5,0.8,1) node[anchor=east]{$F_D$};
\draw[thick,tdplot_main_coords,->,>=latex'] (1,1,1)
-- (1.5,1.5,1) node[anchor=south]{$F_R$};

\draw[dashed,tdplot_main_coords] (0.2,0,1)-- (-0.2,0,1);
\draw[dashed,tdplot_main_coords] (0,0.2,1)-- (0,-0.2,1);

\tdplotdrawarc[tdplot_main_coords,color=blue,->]{(0,0,0)}{0.5}{0}%
{45}{anchor=north,color=black}{$\Omega t+\phi'$}
\end{tikzpicture}

\end{document}

相关内容