【问题标题】:matlab sphere definition as txt filematlab球体定义为txt文件
【发布时间】:2015-03-06 22:52:53
【问题描述】:

我写了一个matlab文件来生成一个3D球体:

obstacle.origin_x=1.6;
obstacle.origin_y=0.8;
obstacle.origin_z=0.2;
obstacle.radius_obs=0.2;
save('obstacle.mat', 'obstacle');

我找到了适合我的问题的代码,但障碍物定义为 .txt 格式

如何将其定义为 .txt 格式?

例如在我找到的代码中,一个直角棱镜定义为:

-0.5000         0    0.5000
0.1500         0    0.5000
0.1500         0   -0.5000
-0.5000         0   -0.5000

0.3500         0    0.5000
0.5000         0    0.5000
0.5000         0   -0.5000
0.3500         0   -0.5000

0.1500         0    0.5000
0.3500         0    0.5000
0.3500         0    0.3500
0.1500         0    0.3500

0.1500         0    0.1500
0.3500         0    0.1500
0.3500         0   -0.5000
0.1500         0   -0.5000

【问题讨论】:

标签: matlab geometry matlab-figure


【解决方案1】:

很难理解你的问题...这是我的解释:

您想在 txt 文件中定义球体的光栅点(=“障碍物”),而不是仅在结构中定义球体的参数?

如果这是真的,您首先必须自己计算球体的所有光栅点,然后您可以将它们打印到文本文件中,例如使用 fprintf。

我写了一个绘制球体的简短函数:

function drawsphere()

bound_horz = 360*pi/180;    % horizontal angle boundaries
bound_vert = 90*pi/180;     % vertical angle boundaries
stepsize = 30;              % discretization step size
r = 400;                    % radius of sphere

% define angle raster points
[theta,phi] = meshgrid(linspace(-bound_horz,bound_horz,stepsize),linspace(-bound_vert,bound_vert,stepsize));
% convert them to Cartesian coordinates
x = r.*cos(theta).*cos(phi);
y = r.*sin(theta).*cos(phi);
z = r.*sin(phi);

C1 = zeros(size(x));
C2 = zeros(size(x));
C3 = ones(size(x));
col = cat(3,C1,C2,C3);

% draw the sphere
fig333=figure(333);clf
cameratoolbar(fig333,'Show')
cameratoolbar(fig333,'SetMode','orbit')
axis vis3d
surf(x,y,z,col);

最后添加 fprintf-calls 以将 x/y/z 写入 .txt 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多