How to plot 2d sector at a height using surf command?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mohammed Aadil Ahmed
le 6 Nov 2022
Commenté : Star Strider
le 9 Nov 2022
Hi,
I have an existing plot done by surf plot command in my script. I would like to do a hold on and superimpose a pizzaslice plot as shown below with following parameters. radius of sector=40 units. angle of sector is 50degrees. height of the sector is 7 units.

What commands can i use for ? meshgrid wont apply to me as i do not want to fill in the spaces outside the pizza slice shape.
2 commentaires
Walter Roberson
le 6 Nov 2022
You start with meshgrid() on a 2D grid. Then you apply transforms to the points to get a new grid.
If the transforms were linear then you could use makehgtform to assist in creating the transformation matrix.
Réponse acceptée
Star Strider
le 7 Nov 2022
Try something like this —
a = linspace(0, 50); % Angle Vector
r = 40; % Radius
p = 90; % Phase
xo = 10; % X-Offset
yo = 5; % Y-Offset
x = xo + r*cosd(a + p);
y = yo + r*sind(a + p);
figure
surf([1;1].*[0 x 0], [1;1].*[0 y 0], [0;7].*ones(2,(numel(a)+2)), 'FaceColor','r', 'EdgeColor','none')
hold on
patch([zeros(size(x)) x], [zeros(size(y)) y], 0*ones(1,numel(a)*2), 'r')
patch([zeros(size(x)) x], [zeros(size(y)) y], 7*ones(1,numel(a)*2), 'r')
hold off
axis('equal')
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Original')
figure
hs = surf([1;1].*[0 x 0], [1;1].*[0 y 0], [0;7].*ones(2,(numel(a)+2)), 'FaceColor','r', 'EdgeColor','none');
hold on
hp{1} = patch([zeros(size(x)) x], [zeros(size(y)) y], 0*ones(1,numel(a)*2), 'r');
hp{2} = patch([zeros(size(x)) x], [zeros(size(y)) y], 7*ones(1,numel(a)*2), 'r');
hold off
axis('equal')
direction = [0.22 0.55 0.77];
angles = 180;
rotate([hs,hp{:}], direction, angles)
xlabel('X')
ylabel('Y')
zlabel('Z')
title(sprintf('Rotated: X = %.1f°, Y = %.1f°, Z = %.1f°', direction*angles))
xt = 10; % Translate Before Rotating
yt = 15; % Translate Before Rotating
zt = 25; % Translate Before Rotating
figure
hs = surf([1;1].*[0 x 0]+xt, [1;1].*[0 y 0]+yt, [0;7].*ones(2,(numel(a)+2))+zt, 'FaceColor','r', 'EdgeColor','none');
hold on
hp{1} = patch([zeros(size(x)) x]+xt, [zeros(size(y)) y]+yt, 0*ones(1,numel(a)*2)+zt, 'r');
hp{2} = patch([zeros(size(x)) x]+xt, [zeros(size(y)) y]+yt, 7*ones(1,numel(a)*2)+zt, 'r');
hold off
axis('equal')
direction = [0.33 0.22 0.66];
angles = 180;
rotate([hs,hp{:}], direction, angles)
xlabel('X')
ylabel('Y')
zlabel('Z')
zlim([0 max(zlim)])
title(sprintf('Translated, Then Rotated: X = %.1f°, Y = %.1f°, Z = %.1f°', direction*angles))
It starts out by creating a hollow surf object, then uses patch to add the top and bottom solid faces, and then uses rotate to rotate it. To translate it, add whatever constants to it you want, then rotate it. Experiment to get the desired result.
.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


