我想绘制“速度场”或“矢量场”,如下所示:
我曾尝试使用 PGFplots“quiver”,但这仅适用于表面上的矢量场:
\begin{tikzpicture}
\begin{axis}[
domain=0:1,
xmax=1,
ymax=1,
]
\addplot3[cyan,/pgfplots/quiver,
quiver/u=y,
quiver/v=z,
quiver/w=x,
quiver/scale arrows=0.1,
-stealth,samples=10] ({x},{y},{x+y});
\end{axis}
\end{tikzpicture}
有没有在 3D 格子上绘制矢量的机制?
for i from 1 to 10
for j from 1 to 10
for k from 1 to 10
draw vector (i,j,k) -- f(i,j,k);
end do;
end do;
end do;
在 PGFplots 或 Tikz 中?(如此处所示:渐近线中的 3D 矢量场)
答案1
你可以像下面的刺猬示例一样手动在 z 方向上展开图层\pgfplotsinvokeforeach
。我不能使用你的例子,因为参数函数f = (x,y,x+y)
实际上是一個表面。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=-1:1,
samples=10,
xmin=-1,xmax=1,
ymin=-1,ymax=1,
zmin=-1,zmax=1,
]
\pgfplotsinvokeforeach{-1,-.5,0,.5,1}{
\addplot3[cyan,quiver,-stealth,
point meta={sqrt((x)^2+(y)^2+(z)^2)},
quiver={
u={x/sqrt((x)^2+(y)^2+(z)^2)},
v={y/sqrt((x)^2+(y)^2+(z)^2)},
w={z/sqrt((x)^2+(y)^2+(z)^2)},
colored,scale arrows=.1}]
(x,y,#1);
}
\end{axis}
\end{tikzpicture}
\end{document}
答案2
这是用 3D Asymptote 绘制的插图。我将速度的长度标准化(cyan
表示小,magenta
表示大,以方便理解)。当然,我们也可以平滑地将颜色从 更改cyan
为magenta
。
size(10cm);
import three;
currentprojection=orthographic(4,2,1,zoom=.9);
triple f(real x, real y, real z){
return (y,z,x);
}
dot(O,2mm+red);
int n=3;
triple A=(0,0,0), B=(n,n,n);
draw(box(-B,B),gray);
for(int i=-n; i<n; ++i)
for(int j=-n; j<n; ++j)
for(int k=-n; k<n; ++k)
{
triple Ms=(i,j,k), Me=f(i,j,k);
pen p;
if (abs(Me-Ms)<4) p=cyan+opacity(.5);
else p=magenta+opacity(.5);
draw(Me--Me+.5*unit(Ms-Me),p,Arrow3);
}
答案3
按照自己的想法:
\documentclass[margin=1cm]{standalone}
\usepackage[pdftex]{graphicx}
\usepackage{pgfplots,tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{decorations.markings,arrows}
\pgfplotsset{compat=newest}
\usepackage{amsmath}
\tdplotsetmaincoords{60}{120}
\begin{document}
\begin{tikzpicture}[scale=1.4]
% scale
\pgfmathsetmacro{\s}{0.15}
\foreach \i in {-0.8,-0.6,...,0.8}
\foreach \j in {-0.8,-0.6,...,0.8}
\foreach \k in {-0.8,-0.6,..., 0.8}
\draw[->, color=cyan, line width=0.2pt]
(\i, \j, \k) -- (\i+ \s*\j, \j + \s*\k, \k + \s*\i);
% draw the cube
\draw[] (-1,1,1)--(1,1,1);
\draw[] (-1,1,-1)--(1,1,-1);
\draw[] (-1,1,1)--(-1,1,-1);
\draw[] (1,1,1)--(1,1,-1);
\draw[] (-1,-1,1)--(1,-1,1);
\draw[] (-1,-1,-1)--(1,-1,-1);
\draw[] (-1,-1,1)--(-1,-1,-1);
\draw[] (1,-1,1)--(1,-1,-1);
\draw[] (-1,1,1)--(-1,-1,1);
\draw[] (-1,1,-1)--(-1,-1,-1);
\draw[] (-1,1,1)--(-1,-1,1);
\draw[] (1,1,1)--(1,-1,1);
\draw[] (1,1,-1)--(1,-1,-1);
\end{tikzpicture}
\end{document}