我希望使用 TikZ 尽可能类似地绘制三维空间的坐标系,该坐标系具有一条通过原点的线,如上图所示。但是我找到的图形示例有网格或刻度。有没有有用的代码可以绘制这个?
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%\psset{algebraic,arrows=<->} ? failed... what should I put?
\end{tikzpicture}
\end{document}
[仍然很难确定所需的角度和长度....]
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
axisline/.style={very thick,-stealth},
rotate around y=10,
]
\draw [axisline] (-3,0,0) -- (3,0,0) node[right]{$x_2$};
\draw [axisline] (0,-3,0) -- (0,3,0) node[left]{$x_3$};
\draw [axisline, cyan] (0,0,1) -- (1,1,2) node[right]{$x_k$};
\draw [axisline] (0,0,1) -- (1,1,2) node[right]{$v$};
\end{tikzpicture}
\end{document}
[制作了类似的图片]
\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[axisline/.style={very thick, -stealth}]
\draw[axisline] (-3,1,0)--(3,-1,0) node[right]{$x_2$};
\draw[axisline] (0,-2.5,0)--(0,3,0) node[above]{$x_3$};
\draw[axisline] (0,0,-3)--(0,0,4) node[below left]{$x_1$};
\draw[cyan] (1, 3, 0)--(-1, -3, 0);
\draw[axisline] (0,0,0)--(0.4,1.2,0) node[right]{$v$};
\end{tikzpicture}
\end{document}
答案1
TikZ 允许您在三维中指定坐标,因此只需画一些线条即可。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
axisline/.style={very thick,-stealth},
rotate around y=10,
]
\draw [axisline] (-3,0,0) -- (3,0,0) node[right]{$x_1$};
\draw [axisline] (0,-3,0) -- (0,3,0) node[right]{$x_2$};
\draw [axisline] (0,0,-3) -- (0,0,3) node[right]{$x_3$};
\draw [cyan] (-2,-2,-2) -- (2,2,2);
\draw [thick,-latex] (0,0,0) -- (1,1,1) node[right]{$\mathbf{v}$};
\end{tikzpicture}
\end{document}
答案2
你可以从使用自定义单位向量绘制 3D 轴网格:
笔记:
- 我也保留了代码
\DrawCoordinateGrid
但注释掉了对此的调用。
代码:
\documentclass{standalone}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{3d}
\makeatletter
%% Apply fix from https://tex.stackexchange.com/questions/48774/drawing-axis-grid-in-3d-with-custom-unit-vectors
\tikzoption{canvas is xy plane at z}[]{%
\def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
\def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
\def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
\tikz@canvas@is@plane
}
\makeatother
\NewDocumentCommand{\DrawCoordinateGrid}{O{} m m m m m m}{%
\def\XGridMin{#2}
\def\XGridMax{#3}
\def\YGridMin{#4}
\def\YGridMax{#5}
\def\ZGridMin{#6}
\def\ZGridMax{#7}
%
\begin{scope}[canvas is xy plane at z=0, thick, red]
\draw [#1] (\XGridMin,\YGridMin) grid (\XGridMax,\YGridMax);
\end{scope}
\begin{scope}[canvas is yz plane at x=0, thin, blue]
\draw [#1] (\YGridMin,\ZGridMin) grid (\YGridMax,\ZGridMax);
\end{scope}
\begin{scope}[canvas is xz plane at y=0, thin, orange]
\draw [#1] (\XGridMin,\ZGridMin) grid (\XGridMax,\ZGridMax);
\end{scope}
}%
\NewDocumentCommand{\DrawCoordinateAxis}{O{} m m m m m m}{%
\def\XAxisMin{#2}
\def\XAxisMax{#3}
\def\YAxisMin{#4}
\def\YAxisMax{#5}
\def\ZAxisMin{#6}
\def\ZAxisMax{#7}
%
\begin{scope}[thin, gray, -latex]
\draw [#1] (\XAxisMin,0,0) -- (\XAxisMax,0,0) node [below left] {$x$};
\draw [#1] (0,\YAxisMin,0) -- (0,\YAxisMax,0) node [right] {$y$};
\draw [#1] (0,0,\ZAxisMin) -- (0,0,\ZAxisMax) node [above] {$z$};
\end{scope}
}%
\begin{document}
\begin{tikzpicture}[
x={(1.0cm,0.0cm)}, y={(0.0cm,1.0cm), z={(-0.5cm,-0.1cm)}}% All grids are ok
]
%\DrawCoordinateGrid{0}{4}{0}{4}{0}{4}
\DrawCoordinateAxis[thick, black]{-2}{5}{-2}{5}{-2}{5}
\draw [thin, blue] (-2,-3,-5) -- (2,3,5);
\draw [ultra thick, red, -stealth] (0,0,0) -- (1,1.5,2.5);
\end{tikzpicture}
%
\begin{tikzpicture}[
x={(-0.5cm,-0.5cm)}, y={(0.9659cm,-0.25882cm)}, z={(0cm,1cm)}% x-y grid is wacky
]
%\DrawCoordinateGrid{0}{4}{0}{4}{0}{4}
\DrawCoordinateAxis[thick, black]{-2}{5}{-2}{5}{-2}{5}
\draw [thin, blue] (-2,-3,-5) -- (2,3,5);
\draw [ultra thick, red, -stealth] (0,0,0) -- (1,1.5,2.5);
\end{tikzpicture}
\end{document}