Increase the dispersion range of the points plotted within the sphere

조회 수: 4 (최근 30일)
I am working with the FAQ Solution to 'How do I create a set of random locations on the surface of a sphere?' and I am trying to increase the dispersion of the points within the hemisphere I have setup. Currently, the points are a bit too clustered around the center of the sphere and I haven't been able to get more points farther away from the center. I know I have to edit line 55 r = bsxfun(@rdivide, r, sqrt(sum(r.^2,1))); But I haven't been able to change it properly to get the result Im looking for. Here is what I have below any help would be greatly appreciated.
clear
clc
% 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 Outerboundary 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 Starting 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');
%%
% Create Set of Random Points to be Plotted inside Hemisphere
n = 200;
A = zeros(n,3);
radius = 76;
% Generate random points
r = randn(n,3);
r = bsxfun(@rdivide, r, sqrt(sum(r.^2,1)));
r = radius*r;
% 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');
  댓글 수: 4
Bruno Luong
Bruno Luong 2020년 8월 31일
편집: Bruno Luong 2020년 8월 31일
Yes you are summing along a wrong dimension. It should be along the dimension of the 3-coordinates, meaning dimension 2 in YOUR case.
Nnamdi Chukwunenye
Nnamdi Chukwunenye 2020년 8월 31일
Yeah I see what you mean I didnt mean to flip the source code from the FAQ, but Im dyslexic so that happens from time to time and I just miss it. Thank you for clearing that up for me.

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2020년 8월 31일
편집: Bruno Luong 2020년 8월 31일
This code generates randomly n 3D points unifformly distributed inside the hemi sphere r < radius and z > 0.
radius = 76;
n = 2000;
s = randn(3,n); % PLEASE DO NOT TRANSPOSE
r = (rand(1,n)).^(1/3);
c = r./sqrt(sum(s.^2,1));
r = radius * (s .* c);
x = r(1,:);
y = r(2,:);
z = abs(r(3,:));
scatter3(x, y, z, 'filled', 'r')
axis equal

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by