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

 채택된 답변

Chris Dan
Chris Dan 2022년 3월 29일

0 개 추천

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')

추가 답변 (1개)

KSSV
KSSV 2022년 3월 29일

0 개 추천

The shape is spherical and looks fine. You need to set the axis. Try
axis equal
at the end.

댓글 수: 1

i found out the answer
theta = atan2(sqrt(X.^2+Y.^2),Z);

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

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2022년 3월 29일

댓글:

2022년 3월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by