Plot area with equation

1 次查看(过去 30 天)
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-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
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 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by