使用MATLAB生成三维空间平面上的点并绘制平面

效果图:
在这里插入图片描述
生成的三维点可以测试优化算法等
代码如下:

% 生成平面仿真数据

%1. 在D维线性空间生成d=D-1维超平面上的点N个

D = 3;
d = D-1;
N = 50;
M = 200;

inliers_gaussian_miu = 0;
inliers_gaussian_sigma = 0.05;

X = [randn(d, N);zeros(1, N)];

scatter3(X(1,:),X(2,:),X(3,:));

% 为inliers点加一点高斯噪声
%X = X + [zeros(d,N);sqrt(inliers_gaussian_sigma)*randn(1,N)];

O = randn(D,M);

X_all = [X O];

% 将数据旋转并添加平移,生成一个高斯分布并进行SVD分解得到旋转矩阵
rotation = orth(randn(D,D));
translation = randn(D,1);
X_all = rotation*X_all + translation;

poly_points = [-1,-1,0;-1,1,0;1,1,0;1,-1,0];
poly_points = poly_points';
poly_points = rotation*poly_points+translation;
C = [0.3,0.2,0.1,0.2];


hold on;
fill3(poly_points(1,:),poly_points(2,:),poly_points(3,:),C);
alpha(.3);
shading interp; % 色彩插值https://blog.csdn.net/mxr2026588745/article/details/108928622



hold on;
scatter3(X_all(1,:),X_all(2,:),X_all(3,:));

hold on;
scatter3(X_all(1,1:N),X_all(2,1:N),X_all(3,1:N));

猜你喜欢

转载自blog.csdn.net/u013238941/article/details/128091157