フィルターのクリア

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 Center および File ExchangeDelaunay Triangulation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by