Rescale multiple spheres on the same 3d plot
이전 댓글 표시
I am trying to plot multipe spheres of different sizes on the same 3D plot. I'd like the spheres placed closest to the origin to be the largest and the smallest ones furtherest away. I've tried sending a vector into the function function to control how many faces the sphere will have, but I get this error. The line numebrs in the error code don't match up exaclty because I have commented out my previous attempts at fixing the problem that don't apply.
Error in sphere (line 29)
cosphi = cos(phi); cosphi(1) = 0; cosphi(n+1) = 0;
Error in BioM3D_SphereTest>createspheres (line 83)
[x, y, z] = sphere(n);
Error in BioM3D_SphereTest (line 71)
[x_loc,y_loc,z_loc, spheresXYZ{i}] = createspheres(FNA_x(i),FNA_y(i),FNA_z(i), n(i,1));
Below is my code. Any help or ideas would be appreciated.
clear
close
clc
A = [0,0,0;0.00977495601952172,0.0129188554738323,0.999868768093125;-0.566794094824837,-0.823750570492204,0.0133959578031223;0.0279587435128966,0.0380588867245362,1.99938731654588;0.830388266617646,0.583999369869120,0.978401571089338;-1.07826433834531,-1.64452537544960,0.267810795303313;0.168715496407312,0.263085998125572,2.96351922435162;-0.791458202545459,0.611268411797120,0.998070417818667;-1.41124221175034,-0.289407593850698,0.0506110237693017;1.69942938355116,1.04462646221878,1.15892918358242;-1.55216375501531,-2.44987966243271,0.623934110066297;0.188310075544404,0.501770043093754,3.93441879647330;-1.44603145623221,1.35107113546187,1.15371676572365;-2.35391403973316,0.0183196401577155,0.179737992978120;2.59879677816763,1.38804628951095,1.42948622326796;-1.92629974765512,-3.28302931738291,1.03122259685150;0.190461468181228,0.731318108759712,4.90771374511875;-2.01837467713375,2.14014570650778,1.37684130228734;-3.30531517848174,0.217844651708771,0.414313445558867;3.50709118523837,1.65551615551852,1.75113998255253;-2.23204460424917,-4.13488361866807,1.45650407075820;0.193343935566412,0.934427321909631,5.88686559182864;-2.51244231909718,2.97180232130260,1.63030617210704;-4.25650570961388,0.357419056329789,0.689550723301627;4.41845060685608,1.87363023778730,2.10021053665969];
x = A(:, 1);
y = A(:, 2);
z = A(:, 3);
% Create Hemisphere Domain
[x_dom,y_dom,z_dom] = sphere(80); %Create Sphere
x_dom = x_dom(41:end,:); % Keep top 41 x points
y_dom = y_dom(41:end,:); % Keep top 41 y points
z_dom = z_dom(41:end,:); % Keep top 41 z points
hemisphere_radius = 80;
figure();
Hemi_sf = surf(hemisphere_radius.*x_dom,hemisphere_radius.*y_dom,hemisphere_radius.*z_dom, 'FaceColor','#4DBEEE','EdgeColor', 'none');
alpha 0.2 %Sets transparency of boundary hemisphere
axis equal
x_ax_lab = xlabel('x axis', 'Color', '#4DBEEE');
y_ax_lab = ylabel('y axis', 'Color', '#4DBEEE');
z_ax_lab = zlabel('z axis', 'Color', '#4DBEEE');
% Plot Outerboundary Circular Plane
x_c = 0;
y_c = 0;
z_c = 0;
radii_plane = 80;
radii_vein = 1;
center_plane = [x_c, y_c]; % center point of circular plane
viscircles(center_plane, radii_plane, 'color', '#77AC30');
hold on
SizeofA = size(A,1);
FNA_x = A(:, 1);
FNA_y = A(:, 2);
FNA_z = A(:, 3);
n = [6.96370042788934;5.96370042788934;5.96370042788934;4.96375547570639;5.55378214243664;4.97904924545806;3.98374650974911;5.55083110747708;5.52220023318542;4.65666303595053;3.99715084015465;2.99294670513842;4.67296636191766;4.60286314806927;3.68897172789716;3.02005588750933;1.99814346506139;3.71566225784534;3.62540440258680;2.70847851108481;2.04428077071202;1;2.74447376195869;2.63691531214705;1.72499063143428];
% Create Spheres
for i = 1:SizeofA
[x_loc,y_loc,z_loc, spheresXYZ{i}] = createspheres(FNA_x(i),FNA_y(i),FNA_z(i), n(i,1));
h(i) = surf(x_loc, y_loc, z_loc,'FaceColor', 'k');
end
function [X,Y,Z,spheresXYZ] = createspheres(spherex, spherey, spherez, n)
[x, y, z] = sphere(n);
X = (x+spherex);
Y = (y+spherey);
Z = (z+spherez);
spheresXYZ = [X,Y,Z];
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



