필터 지우기
필터 지우기

Plot area with equation

조회 수: 2 (최근 30일)
Alex Lee
Alex Lee 2020년 7월 17일
댓글: Alex Lee 2020년 7월 18일
Hello everyone,
I want to plot an area on a sphere, which is defined with the following equations:
R = 50
could somebody help?
Best regards
Alex

채택된 답변

Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020년 7월 17일
편집: Abdolkarim Mohammadi 2020년 7월 18일
r = 50;
NumPoints = 500;
[UnitX,UnitY,UnitZ] = sphere (NumPoints);
RealX = r * UnitX;
RealY = r * UnitY;
RealZ = r * UnitZ;
x = RealX(:);
y = RealY(:);
z = RealZ(:);
Mask = 2.*y .* (sqrt(r.^2-x.^2-y.^2)./(r.^2)).* sind(15) ...
+ ((r.^2-2*x.^2-2*y.^2)./(r.^2)) .* cosd(15) ...
>= cosd(5.8);
% ----------------
figure ('Position', [62,182,1172,338]);
MaskPatchPositive = all ([Mask,z>0], 2);
MaskPatchNegative = all ([Mask,z<0], 2);
% ----------------
subplot (1,3, 1);
hold on
surf (RealX,RealY,RealZ, ...
'EdgeAlpha', 0.05, ...
'FaceAlpha', 0.05);
scatter3 (x(Mask),y(Mask),z(Mask),9, ...
'MarkerEdgeColor', 'none', ...
'MarkerFaceColor', 'r');
hold off
view ([-35,45]);
grid ('on');
box ('on');
daspect ('auto');
ax = gca;
ax.BoxStyle = 'full';
title ('All points');
% ----------------
subplot (1,3, 2);
hold on
surf (RealX,RealY,RealZ, ...
'EdgeAlpha', 0.1, ...
'FaceAlpha', 0.1);
scatter3 (x(MaskPatchPositive),y(MaskPatchPositive),z(MaskPatchPositive),9, ...
'MarkerEdgeColor', 'none', ...
'MarkerFaceColor', 'r');
hold off
xlim ([-5,5]);
ylim ([0,15]);
zlim ([45,50]);
grid ('on');
box ('on');
daspect ([1,1,1]);
view ([-60,30]);
ax = gca;
ax.BoxStyle = 'full';
title ('Upper part');
% ----------------
subplot (1,3, 3);
hold on
surf (RealX,RealY,RealZ, ...
'EdgeAlpha', 0.1, ...
'FaceAlpha', 0.1);
scatter3 (x(MaskPatchNegative),y(MaskPatchNegative),z(MaskPatchNegative),9, ...
'MarkerEdgeColor', 'none', ...
'MarkerFaceColor', 'r');
hold off
xlim ([-5,5]);
ylim ([0,15]);
zlim ([-50,-45]);
grid ('on');
box ('on');
daspect ([1,1,1]);
view ([-60,30]);
ax = gca;
ax.BoxStyle = 'full';
title ('Lower part');
  댓글 수: 3
Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020년 7월 18일
편집: Abdolkarim Mohammadi 2020년 7월 18일
You are right. I read the post again and realized that I wrote the condition for = cos(5.8) mistakenly, instead of >= cos(5.8). I revised the code and plots and there is no need for Epsilon anymore. You can increase NumPoints to get better accuracy. If the new code is correct, please mark it as the accepted answer. Thanks.
Alex Lee
Alex Lee 2020년 7월 18일
A lot of thanks!!!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Delaunay Triangulation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by