Reputation: 3
My task is to draw such seashell in Matlab.
This is what it's supposed to look like:
My code is
s = linspace(0,2*pi);
t = linspace(0,2*pi);
[s, t] = meshgrid(s, t);
n=2;
a=15;
b=500;
c=10;
X =a.*(1-(t./(2*pi))).*cos(n.*t).*(1+cos(s))+c.*cos(n.*t);
Y =a.*(1-(t./(2*pi))).*sin(n.*t).*(1+cos(s))+c.*sin(n.*t);
Z = b.*(t./(2*pi))+a.*(1-(t./2*pi)).*sin(s);
surf(X,Y,Z ,'LineStyle','none','FaceLighting','phong','EdgeColor','none')
colormap(jet)
camlight right
and this is what that code produces:
I don't understand what the problem is. Why doesn't it look right?
Upvotes: 0
Views: 193
Reputation: 826
Your line here:Z = b.*(t./(2*pi))+a.*(1-(t./2*pi)).*sin(s);
has an algebraical mistake.
It should be: Z = b*(t/(2*pi))+a*(1-(t/(2*pi))).*sin(s);
With yours parametrization I got this result:
And using different parametrization found here I got something like:
and with your parameters same code:
Also use operators like
./
and .*
when you divide and multiply arrays element-vise and there is no need to do it for scalar-array multiplication/division.
Upvotes: 2