Effacer les filtres
Effacer les filtres

Plot area with equation

2 vues (au cours des 30 derniers jours)
Alex Lee
Alex Lee le 17 Juil 2020
Commenté : Alex Lee le 18 Juil 2020
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

Réponse acceptée

Abdolkarim Mohammadi
Abdolkarim Mohammadi le 17 Juil 2020
Modifié(e) : Abdolkarim Mohammadi le 18 Juil 2020
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 commentaires
Abdolkarim Mohammadi
Abdolkarim Mohammadi le 18 Juil 2020
Modifié(e) : Abdolkarim Mohammadi le 18 Juil 2020
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 le 18 Juil 2020
A lot of thanks!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Delaunay Triangulation dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by