필터 지우기
필터 지우기

Spherical Patch in 3D

조회 수: 9 (최근 30일)
Chris Dan
Chris Dan 2022년 3월 29일
댓글: Chris Dan 2022년 3월 29일
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일
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일
The shape is spherical and looks fine. You need to set the axis. Try
axis equal
at the end.
  댓글 수: 1
Chris Dan
Chris Dan 2022년 3월 29일
i found out the answer
theta = atan2(sqrt(X.^2+Y.^2),Z);

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by