Borrar filtros
Borrar filtros

Plot area with equation

2 visualizaciones (últimos 30 días)
Alex Lee
Alex Lee el 17 de Jul. de 2020
Comentada: Alex Lee el 18 de Jul. de 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

Respuesta aceptada

Abdolkarim Mohammadi
Abdolkarim Mohammadi el 17 de Jul. de 2020
Editada: Abdolkarim Mohammadi el 18 de Jul. de 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 comentarios
Abdolkarim Mohammadi
Abdolkarim Mohammadi el 18 de Jul. de 2020
Editada: Abdolkarim Mohammadi el 18 de Jul. de 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 el 18 de Jul. de 2020
A lot of thanks!!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Delaunay Triangulation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by