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

5 ビュー (過去 30 日間)
Mohammed Aadil Ahmed
Mohammed Aadil Ahmed 2022 年 11 月 6 日
コメント済み: Star Strider 2022 年 11 月 9 日
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
Mohammed Aadil Ahmed 2022 年 11 月 7 日
"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.
.
  2 件のコメント
Mohammed Aadil Ahmed
Mohammed Aadil Ahmed 2022 年 11 月 9 日
Thanks!
Star Strider
Star Strider 2022 年 11 月 9 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface 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