
Generate randomly placed spheres within a hemisphere domain and calculate the distance between the center of the hemisphere and the random spheres
조회 수: 6 (최근 30일)
이전 댓글 표시
Hello, I am trying to generate randomly placed spheres inside of a defined hemisphere domain. I would like the spheres to be generated in a spherical pattern. Would I need to use spherical coordinates converted to euclidean coordinates with a scatter3 'filled' plot for this part? Next, I want to calculate the distance between a sphere placed at the origin of the domain and the new spheres. From my understanding that would require me to calculate the distance between 2 surfaces or a surface and multiple points, but from my research I have not seen any ways to do this in the documentation or answers pages. I have attached my code below that defines the domain and sets the origin hemisphere. Any help is greatly appreciated.
% 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
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 Hemisphere Lower Boundary Circular Plane
x_c = 0;
y_c = 0;
z_c = 0;
radii_plane = 80;
radii_vein = 4;
radii_node = 4;
center_plane = [x_c, y_c]; % center point of circular plane
viscircles(center_plane, radii_plane, 'color', '#77AC30');
hold on
%%
% Place Center Sphere
[x_c,y_c,z_c] = sphere();
x_c = x_c(11:end,:); % Keep top 11 x points
y_c = y_c(11:end,:); % Keep top 11 y points
z_c = z_c(11:end,:); % Keep top 11 z points
center_root = surf(radii_vein.*x_c,radii_vein.*y_c,radii_vein.*z_c, 'FaceColor', 'k');
댓글 수: 0
채택된 답변
Image Analyst
2020년 8월 25일
Do you want the points to be on the outer shell of the hemisphere, or anywhere inside it?

If you have coordinates x, y, z for each point then you can find the distances of the entire group from the origin like this:
distances = sqrt(x(:) .^ 2 + y(:) .^ 2 + z(:) .^2);
댓글 수: 3
Image Analyst
2020년 8월 26일
You can easily adapt the code in the FAQ:
If you can't figure it out, write back.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 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!