生成小球和大球的代码块
clear all
clc
close all
% entorid3D = rand(10,3, 0.1,0.9);
% for c11 = 0.05:0.3:0.95
% for c12 = 0.05:0.3:0.95
% for c13 = 0.05:0.3:0.95
% [x1,y1,z1] = ellipsoid(c11, c12, c13, 0.05, 0.05, 0.05,100);
% surf(x1,y1,z1,'LineStyle','none','FaceColor', 'r') %画出来球
% axis equal %保证各个维度的长短一致
% hold on
% end
% end
% end
% hold on
% Big spere
[xb,yb,zb] = ellipsoid(2.0, 2.0, 2.0, 0.49, 0.49, 0.49,100);
surf(xb,yb,zb,'LineStyle','none','FaceColor', 'c') %画出来球
axis equal %保证各个维度的长短一致
hold on
% Small speres
for c21 = 1.5:1.0:2.9
for c22 = 1.5:1.0:2.9
c23 = 2.0;
[x2,y2,z2] = ellipsoid(c21, c22, c23, 0.25, 0.25, 0.25,100);
surf(x2,y2,z2,'LineStyle','none','FaceColor', 'b') %画出来球
axis equal %保证各个维度的长短一致
end
end
hold on
% Small speres
for c33 = 1.5:1.0:2.9
for c32 = 1.5:1.0:2.9
c31 = 2.0;
[x3,y3,z3] = ellipsoid(c31, c32, c33, 0.25, 0.25, 0.25,100);
surf(x3,y3,z3,'LineStyle','none','FaceColor', 'r') %画出来球
axis equal %保证各个维度的长短一致
end
end
hold on
xlabel('$x_1$', 'Fontsize', 18, 'Interpreter', 'latex')
ylabel('$x_2$', 'Fontsize', 18, 'Interpreter', 'latex')
zlabel('$x_3$', 'Fontsize', 18, 'Interpreter', 'latex')
set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', 14);
set(gcf, 'Renderer', 'zbuffer');
hold on
axis([1 3 1 3 1 3]);
camlight('headlight')
下面的图为画分别平行于 xoy 和 yoz 的截面
clear all
close all
clc
num2xy_point = 30000;
xy_point = rand(num2xy_point, 2);
xy_point(:,1) = 1+xy_point(:,1)*2;
xy_point(:, 2) = 1+xy_point(:, 2)*2;
count_num2xy=1;
for ip2xy = 1:num2xy_point
x1_ip = xy_point(ip2xy,1);
y1_ip = xy_point(ip2xy,2);
% 抠除中心大球
cx1_b = x1_ip-2.0;
cy1_b = y1_ip-2.0;
rcb = sqrt(cx1_b^2+cy1_b^2);
% 抠除小球 1
cx1_1 = x1_ip-1.5;
cy1_1 = y1_ip-1.5;
rc1 = sqrt(cx1_1^2+cy1_1^2);
% 抠除小球 2
cx1_2 = x1_ip-2.5;
cy1_2 = y1_ip-2.5;
rc2 = sqrt(cx1_2^2+cy1_2^2);
% 抠除小球 3
cx1_3 = x1_ip-1.5;
cy1_3 = y1_ip-2.5;
rc3 = sqrt(cx1_3^2+cy1_3^2);
% 抠除小球 4
cx1_4 = x1_ip-2.5;
cy1_4 = y1_ip-1.5;
rc4 = sqrt(cx1_4^2+cy1_4^2);
if rcb>0.49 && rc1>0.25 && rc2>0.25 && rc3>0.25 && rc4>0.25
irregularD1(count_num2xy, 1)=x1_ip;
irregularD1(count_num2xy, 2)=y1_ip;
count_num2xy=count_num2xy+1;
end
end
size2xy_point = size(irregularD1);
irregularD1Z = ones(max(size2xy_point),1)*2.0;
irregularD1X = irregularD1(:, 1);
irregularD1Y = irregularD1(:, 2);
irregularD1XYZ = [irregularD1X,irregularD1Y,irregularD1Z];
num2yz_point = 30000;
yz_point = rand(num2yz_point, 2);
yz_point(:,1) = 1 + yz_point(:,1)*2;
yz_point(:, 2) = 1 + yz_point(:, 2)*2;
count_num2yz=1;
for ip2xy = 1:num2yz_point
y2_ip = yz_point(ip2xy,1);
z2_ip = yz_point(ip2xy,2);
% 抠除中心大球
cy2_b = y2_ip-2.0;
cz2_b = z2_ip-2.0;
rcb2 = sqrt(cy2_b^2+cz2_b^2);
% 抠除小球 1
cy1_1 = y2_ip-1.5;
cz1_1 = z2_ip-1.5;
rc21 = sqrt(cy1_1^2+cz1_1^2);
% 抠除小球 2
cy2_2 = y2_ip-2.5;
cz2_2 = z2_ip-2.5;
rc22 = sqrt(cy2_2^2+cz2_2^2);
% 抠除小球 3
cy2_3 = y2_ip-1.5;
cz2_3 = z2_ip-2.5;
rc23 = sqrt(cy2_3^2+cz2_3^2);
% 抠除小球 4
cy2_4 = y2_ip-2.5;
cz2_4 = z2_ip-1.5;
rc24 = sqrt(cy2_4^2+cz2_4^2);
if rcb2>0.49 && rc21>0.25 && rc22>0.25 && rc23>0.25 && rc24>0.25
irregularD2(count_num2yz, 1)=y2_ip;
irregularD2(count_num2yz, 2)=z2_ip;
count_num2yz=count_num2yz+1;
end
end
size2yz_point = size(irregularD2);
irregularD2X = ones(max(size2yz_point),1)*2.0;
irregularD2Y = irregularD2(:, 1);
irregularD2Z = irregularD2(:, 2);
irregularD2XYZ = [irregularD2X,irregularD2Y,irregularD2Z];
figure('name', 'fig')
scatter3(irregularD1X,irregularD1Y,irregularD1Z,'r.')
hold on
scatter3(irregularD2X,irregularD2Y,irregularD2Z,'c.')
hold on
xlabel('$x_1$', 'Fontsize', 18, 'Interpreter', 'latex')
ylabel('$x_2$', 'Fontsize', 18, 'Interpreter', 'latex')
zlabel('$x_3$', 'Fontsize', 18, 'Interpreter', 'latex')
set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', 14);
set(gcf, 'Renderer', 'zbuffer');
hold on
axis([1 3 1 3 1 3]);
XYZ = [irregularD1XYZ;irregularD2XYZ];
u = 10*exp(-0.25*(XYZ(:,1)+XYZ(:,2)+XYZ(:,3)));
save('TwoSlice2TestXYZ.mat','XYZ')