Max Ostroukhov
Max Ostroukhov

Reputation: 3

What's wrong with my plot of a 3D seashell in Matlab?

My task is to draw such seashell in Matlab.

This is what it's supposed to look like:

enter image description here

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:

enter image description here

I don't understand what the problem is. Why doesn't it look right?

Upvotes: 0

Views: 193

Answers (1)

madbitloman
madbitloman

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: enter image description here

And using different parametrization found here I got something like: enter image description here and with your parameters same code:enter image description here 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

Related Questions