3d Hemisphere transformation Problem from A to 90 degrees in Z axis to B direction
1 view (last 30 days)
Show older comments
Musa Mustapha
on 4 May 2019
Answered: David Goodmanson
on 5 May 2019
%code for A
N=500;
r = 6;
center = [2,1,3];
plot3(center(1),center(2),center(3),'ro')
hold on
P = zeros(N,3) ;
for i=1:N
x1 = rand;
x2 = rand;
Px = r*sqrt(x1*(2-x1))* cos(2*pi*x2);
Py = r*sqrt(x1*(2-x1))* sin(2*pi*x2);
Pz = r*(1-x1);
P(i,:) = [Px, Py, Pz]+center;
end
hold on
plot3(P(:,1), P(:,2), P(:,3),'.r')
to
0 Comments
Accepted Answer
David Goodmanson
on 5 May 2019
Hi Musa,
In the figure you don't say which axis is which, but I will assume +x axis out of the page toward the viewer, +y axis right, +z axis up. With the figure rotated as shown, the old z coordinates are along the +y axis and the old y coordinates are along the -z axis. It's possible to use rotation matrices for this, but in the 90 degree case it's easier to just change the coordinate labels as shown in plot 2 below.
N=1000;
r = 6;
center = [2,1,3];
figure(1)
plot3(center(1),center(2),center(3),'b*')
hold on
P = zeros(N,3) ;
for i=1:N
x1 = rand;
x2 = rand;
Px = r*sqrt(x1*(2-x1))* cos(2*pi*x2);
Py = -r*sqrt(x1*(2-x1))* sin(2*pi*x2);
Pz = r*(1-x1);
P(i,:) = [Px, Py, Pz]+center;
end
hold on
plot3(P(:,1), P(:,2), P(:,3),'.r')
axis equal
xlabel('x'); ylabel('y'); zlabel('z')
hold off
figure(2)
plot3(center(1),center(2),center(3),'b*')
hold on
P = zeros(N,3) ;
for i=1:N
x1 = rand;
x2 = rand;
Px = r*sqrt(x1*(2-x1))* cos(2*pi*x2);
Pz = -r*sqrt(x1*(2-x1))* sin(2*pi*x2);
Py = r*(1-x1);
P(i,:) = [Px, Py, Pz]+center;
end
hold on
plot3(P(:,1), P(:,2), P(:,3),'.r')
view([4 -1.2 .8])
xlabel('x'); ylabel('y'); zlabel('z')
axis equal
hold off
.
0 Comments
More Answers (0)
See Also
Categories
Find more on Signal Generation and Preprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!