Spherical Patch in 3D

6 vues (au cours des 30 derniers jours)
Chris Dan
Chris Dan le 29 Mar 2022
Commenté : Chris Dan le 29 Mar 2022
Hello,
I am trying to make a 3d spherical segment. I am having problems with the atan2 function. in 2D my code is
clear all; close all;
p = linspace(-1/2,1/2,200);
[X,Y] = meshgrid(p,p); % box mesh
R = p(size(p,2))/2;
r = R/1.5;
alpha = deg2rad(45);
theta = atan2(Y,X);
f = figure('visible','on');
active = (X.^2 + Y.^2 <= R^2) & (X.^2 + Y.^2 >= r^2);
plot(X(active),Y(active),'o','MarkerFaceColor','blue');
active = (X.^2 + Y.^2 <= R^2) & (X.^2 + Y.^2 >= r^2) & (abs(theta)< alpha);
hold on
plot(X(active),Y(active),'o','MarkerFaceColor','red');
here every thing is as I want(the red patch) ,but when I try to make the same patch in 3D, I am getting getting the wrong shape.
here is my code:
clear all; close all;
p = linspace(-1/2,1/2,100);
[X,Y,Z] = meshgrid(p,p,p); % box mesh
R = p(size(p,2))/2;
r = R/1.5;
alpha = deg2rad(45);
f = figure('visible','on');
theta = atan2(Z,X);
active = (X.^2 + Y.^2 + Z.^2 <= R^2) & (X.^2 + Y.^2 +Z.^2 >= r^2);
plot3(X(active),Y(active),Z(active),'o','MarkerFaceColor','blue');
active = (X.^2 + Y.^2 + Z.^2 <= R^2) & (X.^2 + Y.^2 +Z.^2 >= r^2) & (abs(theta) <= alpha);
hold on
plot3(X(active),Y(active),Z(active),'o','MarkerFaceColor','red');
saveas(f,'3d_patch','fig')
Can anyone tell me what is wrong? I figured it out to be theta...
Does any one knows how to take correct angle

Réponse acceptée

Chris Dan
Chris Dan le 29 Mar 2022
I found out the answer
clear all; close all;
p = linspace(-1/2,1/2,100);
[X,Y,Z] = meshgrid(p,p,p); % box mesh
R = p(size(p,2))/2;
r = R/1.5;
alpha = deg2rad(45);
f = figure('visible','on');
theta = atan2(sqrt(X.^2+Y.^2),Z);
active = (X.^2 + Y.^2 + Z.^2 <= R^2) & (X.^2 + Y.^2 +Z.^2 >= r^2);
plot3(X(active),Y(active),Z(active),'o','MarkerFaceColor','blue');
active = (X.^2 + Y.^2 + Z.^2 <= R^2) & (X.^2 + Y.^2 +Z.^2 >= r^2) & (abs(theta) <= alpha);
hold on
plot3(X(active),Y(active),Z(active),'o','MarkerFaceColor','red');
saveas(f,'3d_patch','fig')

Plus de réponses (1)

KSSV
KSSV le 29 Mar 2022
The shape is spherical and looks fine. You need to set the axis. Try
axis equal
at the end.
  1 commentaire
Chris Dan
Chris Dan le 29 Mar 2022
i found out the answer
theta = atan2(sqrt(X.^2+Y.^2),Z);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by