Generate randomly placed spheres within a hemisphere domain and calculate the distance between the center of the hemisphere and the random spheres

3 ビュー (過去 30 日間)
Nnamdi Chukwunenye 2020 年 8 月 25 日
コメント済み: Nnamdi Chukwunenye 2020 年 8 月 27 日
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
figure();
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;
center_plane = [x_c, y_c]; % center point of circular plane
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

サインインしてコメントする。

採用された回答

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 件のコメント表示非表示 2 件の古いコメント
Nnamdi Chukwunenye 2020 年 8 月 27 日
Hi, I adapted the FAQ soln into my code and was succesfully able to generate the random points inside of the hemisphere. Thank you for your help with that, but the second part of my problem is calculating the distance between the surface of the sphere are the center of the domain and scattered points around it. I want eliminate the points that lie within a certain distance (d=16) from the surface of hemisphere located at the center of the domain.
% Create Set of Random Points to be Plotted inside Hemisphere
n = 50;
A = zeros(n,3);
% Generate random points
r = randn(n,3);
r = bsxfun(@rdivide, r, sqrt(sum(r.^2,1)));
% Extract the x, y, and z coordinates from the array.
x = r(:,1); % Extract x from column #1.
y = r(:,2); % Extract y from column #2.
z = abs(r(:,3)); % Extract z from column #3.
A = [x, y, z]; % stores random points generated
BioM_3Dgraph1 = scatter3(x, y, z, 'filled', 'r');

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by