有没有一种方法可以使用scatter3在3D点云散点图上显示2D投影?

时间:2019-05-10 18:12:14

标签: matlab

我使用scatter3函数绘制3D点云结果。现在,我想将散射点的2D投影绘制到例如Y-Z平面上。

理想的结果应该是3D矩阵中的散射点云以及Y-Z平面上的2D投影。我该怎么办?

2 个答案:

答案 0 :(得分:0)

如果仅将X,Y或Z的所有元素设置为单个值,则将所有点投影到该平面。我投影到X = 1平面,因为它位于图的后面并且看起来更好。

Points = rand(50,3);
scatter3(Points(:,1),Points(:,2),Points(:,3),'.');
hold on
scatter3(ones(size(Points(:,1))),Points(:,2),Points(:,3),'+')
hold off

答案 1 :(得分:0)

这是一个脚本,其功能类似于您想要的

% generate random data
n = 64;
x = zeros(n,3);
for k = 1:3
    x(:,k) = randi(4) * randn(n,1) + randi(8);
end
x(:,4) = randi([8,16],n,1);
x(:,5) = randi(256,n,1);

% generate scatter plot
h = scatter3(x(:,1),x(:,2),x(:,3),x(:,4),x(:,5));
h.MarkerFaceColor = 'flat';

% get axes handle
hAx = gca;
hAx.XLabel.String = 'x';
hAx.YLabel.String = 'y';
hAx.ZLabel.String = 'z';

% get axes slices
xSlice = hAx.XLim(2);
ySlice = hAx.YLim(2);
zSlice = hAx.ZLim(1);

% add projected markers
hAx.NextPlot = 'add';
hAx.Box = 'on';
% xy plane
h(2) = scatter3(x(:,1),x(:,2),zSlice*ones(n,1),x(:,4),x(:,5));
% zy plane
h(2) = scatter3(xSlice*ones(n,1),x(:,2),x(:,3),x(:,4),x(:,5));
% xz plane
h(3) = scatter3(x(:,1),ySlice*ones(n,1),x(:,3),x(:,4),x(:,5));
view(-45,30)
相关问题