How can I create sphere in this code?
4 ビュー (過去 30 日間)
古いコメントを表示
X=(0:0.02:1);
Y=(0:0.02:1);
[x,y] = meshgrid(X,Y);
%z=rand(size(x))*1000;
%z=1e6*ones(size(x));
z=zeros(size(x));
x0=mean(X);
y0=mean(Y);
b_center1 = [0.2,0.8];
b_center2 = [0.6,0.2];
b_center3 = [0.4,0.55];
r1=0.1*max(X);
r2=0.1*max(X);
r3=0.1*max(X);
for i=1:length(X)
for j=1:length(Y)
dist = pdist([[X(i),Y(j)];b_center1]);
if (dist < r1)
z(i,j)=1;
end
dist = pdist([[X(i),Y(j)];b_center2]);
if (dist < r2)
z(i,j)=1;
end
dist = pdist([[X(i),Y(j)];b_center3]);
if (dist < r3)
z(i,j)=1;
end
end
end
surf(x,y,z)
0 件のコメント
回答 (1 件)
Ayush Gupta
2020 年 9 月 10 日
The above code is not able to generate spheres primarily because in the workflow any point that is less than r1 is given a true value by giving it 1 whereas for a sphere the points should be all equidistant from a center. To plot a sphere with center at (a,b,c) and radius r, refer to the following code:
[x,y,z] = sphere;
x = x*r;
y = y*r;
z = z*r;
figure
surf(x+a,y+b,z+c)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!