Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Plot a torus

Subject: Plot a torus

From: kawak

Date: 13 Jun, 2010 17:18:03

Message: 1 of 4

Hello,

I would like to plot a basic torus on matlab.

Here is my code:

u=0:0.1:2*pi;
v=0:0.1:2*pi;

a=2;
b=1;

X=(a+b.*cos(v)).*cos(u);
Y=(a+b.*cos(v)).*sin(u);
Z=b.*sin(v);

surf(X,Y,Z)

But it didn't work. Do you know why?

Thank you very much

Benji

Subject: Plot a torus

From: Roger Stafford

Date: 13 Jun, 2010 17:40:08

Message: 2 of 4

"kawak " <kbenjamin@hotmail.fr> wrote in message <hv33sb$300$1@fred.mathworks.com>...
> Hello,
>
> I would like to plot a basic torus on matlab.
>
> Here is my code:
>
> u=0:0.1:2*pi;
> v=0:0.1:2*pi;
>
> a=2;
> b=1;
>
> X=(a+b.*cos(v)).*cos(u);
> Y=(a+b.*cos(v)).*sin(u);
> Z=b.*sin(v);
>
> surf(X,Y,Z)
>
> But it didn't work. Do you know why?
>
> Thank you very much
>
> Benji

  You need to make a "mesh" of your u and v parameters like this:

[u,v] = meshgrid(u,v);

Read the instructions for the 'surf' function to find out about meshes.

Roger Stafford

Subject: Plot a torus

From: us

Date: 13 Jun, 2010 18:29:04

Message: 3 of 4

"kawak " <kbenjamin@hotmail.fr> wrote in message <hv33sb$300$1@fred.mathworks.com>...
> Hello,
>
> I would like to plot a basic torus on matlab.
>
> Here is my code:
>
> u=0:0.1:2*pi;
> v=0:0.1:2*pi;
>
> a=2;
> b=1;
>
> X=(a+b.*cos(v)).*cos(u);
> Y=(a+b.*cos(v)).*sin(u);
> Z=b.*sin(v);
>
> surf(X,Y,Z)
>
> But it didn't work. Do you know why?
>
> Thank you very much
>
> Benji

one of the solutions

     a=5;
     c=10;
     [u,v]=meshgrid(0:10:360);
     x=(c+a*cosd(v)).*cosd(u);
     y=(c+a*cosd(v)).*sind(u);
     z=a*sind(v);
     surfl(x,y,z)
     axis equal;

us

Subject: Plot a torus

From: kawak

Date: 13 Jun, 2010 19:11:04

Message: 4 of 4

Thank you very much for your help!!

Cheers

Benji

"us " <us@neurol.unizh.ch> wrote in message <hv381g$a3m$1@fred.mathworks.com>...
> "kawak " <kbenjamin@hotmail.fr> wrote in message <hv33sb$300$1@fred.mathworks.com>...
> > Hello,
> >
> > I would like to plot a basic torus on matlab.
> >
> > Here is my code:
> >
> > u=0:0.1:2*pi;
> > v=0:0.1:2*pi;
> >
> > a=2;
> > b=1;
> >
> > X=(a+b.*cos(v)).*cos(u);
> > Y=(a+b.*cos(v)).*sin(u);
> > Z=b.*sin(v);
> >
> > surf(X,Y,Z)
> >
> > But it didn't work. Do you know why?
> >
> > Thank you very much
> >
> > Benji
>
> one of the solutions
>
> a=5;
> c=10;
> [u,v]=meshgrid(0:10:360);
> x=(c+a*cosd(v)).*cosd(u);
> y=(c+a*cosd(v)).*sind(u);
> z=a*sind(v);
> surfl(x,y,z)
> axis equal;
>
> us

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us