最近我尝试使用PyPlot/Julia绘制球体,不幸的是它比我想象的要难.点生成可能有问题,但我无法弄清楚为什么我的实现不起作用.虽然原始的python代码一切都很好.
我试图从matplotlib曲面图doc中调整demo2作为MWE:
using PyPlot
u = linspace(0,2*?,100);
v = linspace(0,?,100);
x = cos(u).*sin(v);
y = sin(u).*sin(v);
z = cos(v);
surf(x,y,z)
Run Code Online (Sandbox Code Playgroud)
那么,我的Julia实施中究竟出了什么问题呢?
x,y并z应矩阵,向量不是-否则你只有而非表面本身的球体绘制的曲线.
using PyPlot
n = 100
u = linspace(0,2*?,n);
v = linspace(0,?,n);
x = cos(u) * sin(v)';
y = sin(u) * sin(v)';
z = ones(n) * cos(v)';
# The rstride and cstride arguments default to 10
surf(x,y,z, rstride=4, cstride=4)
Run Code Online (Sandbox Code Playgroud)
最初绘制的曲线对应于那些矩阵的对角线.
plot( diag(x), diag(y), diag(z), color="yellow", linewidth=3 )
Run Code Online (Sandbox Code Playgroud)
这在 Julia 1.1.2 中不再适用于绘制球体。用这个代替
\n\nusing PyPlot\nn = 100\nu = range(0,stop=2*\xcf\x80,length=n);\nv = range(0,stop=\xcf\x80,length=n);\n\nx = cos.(u) * sin.(v)';\ny = sin.(u) * sin.(v)';\nz = ones(n) * cos.(v)';\n\n# The rstride and cstride arguments default to 10\nsurf(x,y,z, rstride=4, cstride=4)\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
1400 次 |
| 最近记录: |