# Increase the dispersion range of the points plotted within the sphere

1 ビュー (過去 30 日間)
Nnamdi Chukwunenye 2020 年 8 月 31 日

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
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 Outerboundary 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 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
%%
% Create Set of Random Points to be Plotted inside Hemisphere
n = 200;
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');

#### 4 件のコメント

Nnamdi Chukwunenye 2020 年 8 月 31 日
Hi Bruno so are you saying that my vector normalization doesn't agree because I'm summing along the wrong dimension ? or is it something else?
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 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 2020 年 8 月 31 日

This code generates randomly n 3D points unifformly distributed inside the hemi sphere r < radius and z > 0.
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

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

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by