Generate sphere whose center is not at origin
How do I generate a sphere with center at [x = 4.26, y = 1.76, z = 1.62] with a radius of 0.25 units? The sphere should have 101 points. The output should look like following figure. In the figure, the blue markers are the first 51 points of the 101 points and the red markers are the remaining 50 points. Attached also find, .fig format of the required output. Below this figure, is my code. However, I am unable to reproduce the required figure. Can anyone please help?
I = imread(‘Sphere.png’);
imshow(I);
%Center of sphere
recPosition = [4.26 1.76 1.62];
rng(0,’twister’);
radius = 0.25;
%Number of points
nPoints = 100;
%Create array
test_xyz = zeros(101,3);
test_xyz(1,1) = recPosition(1);
test_xyz(1,2) = recPosition(2);
test_xyz(1,3) = recPosition(3);
radius = zeros(nPoints,1)+radius ;
azimuth = rand(size(radius)) * 2*pi;
elevation = (rand(size(radius)) .* pi)-pi/2;
[x,y,z] = sph2cart(azimuth,elevation,radius);
test_xyz(2:end,1) = test_xyz(1,1)+x;
test_xyz(2:end,2) = test_xyz(1,2)+y;
test_xyz(2:end,3) = test_xyz(1,3)+z;
figure
scatter3(test_xyz(:,1),test_xyz(:,2),test_xyz(:,3));How do I generate a sphere with center at [x = 4.26, y = 1.76, z = 1.62] with a radius of 0.25 units? The sphere should have 101 points. The output should look like following figure. In the figure, the blue markers are the first 51 points of the 101 points and the red markers are the remaining 50 points. Attached also find, .fig format of the required output. Below this figure, is my code. However, I am unable to reproduce the required figure. Can anyone please help?
I = imread(‘Sphere.png’);
imshow(I);
%Center of sphere
recPosition = [4.26 1.76 1.62];
rng(0,’twister’);
radius = 0.25;
%Number of points
nPoints = 100;
%Create array
test_xyz = zeros(101,3);
test_xyz(1,1) = recPosition(1);
test_xyz(1,2) = recPosition(2);
test_xyz(1,3) = recPosition(3);
radius = zeros(nPoints,1)+radius ;
azimuth = rand(size(radius)) * 2*pi;
elevation = (rand(size(radius)) .* pi)-pi/2;
[x,y,z] = sph2cart(azimuth,elevation,radius);
test_xyz(2:end,1) = test_xyz(1,1)+x;
test_xyz(2:end,2) = test_xyz(1,2)+y;
test_xyz(2:end,3) = test_xyz(1,3)+z;
figure
scatter3(test_xyz(:,1),test_xyz(:,2),test_xyz(:,3)); How do I generate a sphere with center at [x = 4.26, y = 1.76, z = 1.62] with a radius of 0.25 units? The sphere should have 101 points. The output should look like following figure. In the figure, the blue markers are the first 51 points of the 101 points and the red markers are the remaining 50 points. Attached also find, .fig format of the required output. Below this figure, is my code. However, I am unable to reproduce the required figure. Can anyone please help?
I = imread(‘Sphere.png’);
imshow(I);
%Center of sphere
recPosition = [4.26 1.76 1.62];
rng(0,’twister’);
radius = 0.25;
%Number of points
nPoints = 100;
%Create array
test_xyz = zeros(101,3);
test_xyz(1,1) = recPosition(1);
test_xyz(1,2) = recPosition(2);
test_xyz(1,3) = recPosition(3);
radius = zeros(nPoints,1)+radius ;
azimuth = rand(size(radius)) * 2*pi;
elevation = (rand(size(radius)) .* pi)-pi/2;
[x,y,z] = sph2cart(azimuth,elevation,radius);
test_xyz(2:end,1) = test_xyz(1,1)+x;
test_xyz(2:end,2) = test_xyz(1,2)+y;
test_xyz(2:end,3) = test_xyz(1,3)+z;
figure
scatter3(test_xyz(:,1),test_xyz(:,2),test_xyz(:,3)); sphere, sph2cart, radius MATLAB Answers — New Questions