How to plot 2d sector at a height using surf command?

8 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2022-11-6
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.
Mohammed Aadil Ahmed
"Then you apply transforms to the points to get a new grid." but the new grid will still be a rectrangular grid? i didnt get how the new grid becomes a sector with transformation

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2022-11-7
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.
See the documentaion on surf, patch, and rotate for details.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by