TJarrett
TJarrett

Reputation: 41

drawing a 3d seashell in matlab

I have been trying to draw a 3d seashell in Matlab for a while now, but I am having a lot of trouble because I am very new to Matlab. This is the code I've attempted to put together so far with the parameters and equations commented at the beginning...

clear all

close all


%Seashell

%Parameters: 0 <= v <= 2*pi, 0 <= u <= 6*pi

%Equations: x = 2*(1 - e^(u/(6*pi)))*cos(u)*cos^2(0.5v)

%           y = 2*((-1) + e^(u/(6*pi)))*sin(u)*cos^2(0.5v)

%           z = 1 - e^(u/3pi) - sin(v)+ e^u/(6*pi))*sin(v)


for q= 1:1885

    u = 0:0.01:6*pi;

    V = 0:0.01:2*pi;

    for p=1:629

        v=V(:,p);

    end


            x = (2.*(1 - exp(u/(6.*pi))).*cos(u))'*((cos(0.5.*v)).^2);

            y = (2.*(-1 + exp(u/(6.*pi))).*sin(u))'*((cos(0.5.*v)).^2);

            z = 1 - exp(u/(3.*pi)) - sin(v)+ exp(u/(6.*pi)*sin(v));


end


           j=x';

        frog=y'; 

       sam(1,:)=j;

       sam(2,:)=frog;

       sam(3,:)=z;

       mesh(sam)



%z=z'

%test=[z,y,x];

%plot3(x,y,z);

%axis equal;

The problem I am having is that I don't know how to plot the equations together. Can someone take a look at my code and give me some pointers/help on how to fix this?

Thanks so much in advance, -Thomas

Upvotes: 3

Views: 401

Answers (1)

lennon310
lennon310

Reputation: 12689

ezmesh('2.*(1 - exp(u/(6.*pi))).*cos(u)*cos(0.5.*v).^2',...
       '2.*(-1 + exp(u/(6.*pi))).*sin(u)*(cos(0.5.*v)).^2',...
       '1 - exp(u/(3.*pi)) - sin(v)+ exp(u/(6.*pi)*sin(v))',...
       [ 0, 6*pi, 0, 2*pi]);

Upvotes: 1

Related Questions