Talha Yousuf
Talha Yousuf

Reputation: 301

How to plot this cake piece like surface in matlab?

I am trying to plot a cake piece like surface in matlab but I have no idea how to define z to make it look like a cake pie. The shape I need is this: enter image description here This is the code I wrote so far:

th = linspace(0, pi/3);
r = linspace(0, pi/3);
% z = linspace(0, 10);
[R, TH] = meshgrid(r, th);

x = R.*cos(TH);
y = R.*sin(TH);
z = R;
% z = 10 * ones(size(x));
ss = surf(x, y, z, 'FaceAlpha',0.3);
ss.EdgeAlpha = 0.6;
ss.FaceAlpha = 0.1;

Upvotes: 1

Views: 156

Answers (1)

Bilal
Bilal

Reputation: 3854

it will look similar to that shape, but not exactly, I mean the shape will be rough:

z = rand(size(x));

another option with smoother surface:

z = zeros(size(x));
[m,n]=size(x);
for i=1 : n
    for j=1 : m
        if(mod(i+j,2)==0)
            z(i,j) = 1;
        end
    end
end

Upvotes: 1

Related Questions