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

조회 수: 3 (최근 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.
.

추가 답변 (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