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:
problem with 3d solid

Subject: problem with 3d solid

From: misty m.

Date: 11 May, 2008 13:17:02

Message: 1 of 5

hi,
i want to do nice 3d graph, but not using plot3, i would
like to have a solid looking rather like after using 'surf'
or 'mesh', but actually i have some problems:/
my solid is something similiar to cylinder - i have control
points (x,y) of circles and know the distance between them
(z=1), so when i do plot3(x,y,z) i have something similar
to cylinder.
having x,y,z i would like to have a nicer graph that is the
reason i started looking for something different than
plot3. but neither with mesh or surface something is wrong.

can anyone suggest me somtehing? i'm sure the solution is
quite simple, i look a little in google but all i can find
are examples from matlab help using [X,Y,Z]=meshgrid(x,y,z)
that i cannot use as these vectors are too big..

i hole i wrote clearly what my problem is.

kind regards

Subject: problem with 3d solid

From: alessandro mura

Date: 11 May, 2008 14:11:22

Message: 2 of 5

When you use plot3, the shape of the input is not important, i.e.
plot3(x,y,z) and plot3(x(:),y(:),z(:)) may both give a cylinder.

Surf is different because the cylinder surface must be divided into 3
pieces (lateral+top+bottom) and all these 3 pieces must be
rectangular matrixes.

If you are experiencing weird results from surf maybe that is the problem.

Try something like:

[a,z]=ndgrid([0:.1:1]*2*pi,[0:.1:1]);
 x=cos(a);
 y=sin(a);
 surf(x,y,z,x*0)
 hold on
 [a,r]=ndgrid([0:.1:1]*2*pi,[0 1]);
 x=cos(a).*r;
 y=sin(a).*r;
 surf(x,y,x*0,x*0)
 surf(x,y,x*0+1,x*0)



--
Alessandro Mura
Istituto Nazionale di Astrofisica - IFSI
http://pptt4.ifsi-roma.inaf.it/~mura/index.html
http://www.alessandromura.it

Subject: problem with 3d solid

From: misty m.

Date: 11 May, 2008 14:36:02

Message: 3 of 5

maybe i should describe my problem better. i've got 113
figures, similar to circles. i've got control points(x,y)
of each of them. for one circle i can have for example 100
control points, for another one i can have 120. so i put
them into cells:
X={x(ii)}
Y={y{ii}}

now i must plot them as a solid. i decided that the
distance between will be =1. so i have the third coefficient
Z={z(ii)}.

i cannot use any functions (sin/cos etc) to help me
generate my circles and later solid. i can only use my
control points (X,Y,Z).
when i try to use meshgrid to use mesh later, then i got an
error that vectors are too big.
i need somtething as easy as plot3, but giving nicer
results

Subject: problem with 3d solid

From: Roger Stafford

Date: 11 May, 2008 18:33:02

Message: 4 of 5

"misty m." <donotspam@smth.be> wrote in message <g0708i$q5a
$1@fred.mathworks.com>...
> maybe i should describe my problem better. i've got 113
> figures, similar to circles. i've got control points(x,y)
> of each of them. for one circle i can have for example 100
> control points, for another one i can have 120. so i put
> them into cells:
> X={x(ii)}
> Y={y{ii}}
>
> now i must plot them as a solid. i decided that the
> distance between will be =1. so i have the third coefficient
> Z={z(ii)}.
>
> i cannot use any functions (sin/cos etc) to help me
> generate my circles and later solid. i can only use my
> control points (X,Y,Z).
> when i try to use meshgrid to use mesh later, then i got an
> error that vectors are too big.
> i need somtething as easy as plot3, but giving nicer
> results
---------------
  As Alessandro has illustrated, to be able to use 'surf', it is necessary to have
your surface defined in terms of three equal-sized x, y, and z coordinate
two-dimensional (rectangular) arrays. The two indices of the arrays are, in
effect, two parameters for points on the surface being displayed and these
parameters lie within a rectangular mesh defined by the size of the arrays.
This enables the 'surf' function to draw little line segments between any point

 P0 = (x(i,j),y(i,j),z(i,j))

and each of its four neighbors

 P1 = (x(i+1,j),y(i+1,j),z(i+1,j))
 P2 = (x(i,j+1),y(i,j+1),z(i,j+1))
 P3 = (x(i-1,j),y(i-1,j),z(i-1,j))
 P4 = (x(i,j-1),y(i,j-1),z(i,j-1))

It is this association by way of line segments between points and their
neighbors that causes the plot to be "a nicer graph", as you have described it.
It is what distinguishes the output of 'surf' from that of 'plot3'.

  In your problem, the z coordinate itself clearly defines one of your
parameters, but what you refer to as "control points" in your figures have
differing numbers of points in the various figures, leaving you no clear way to
draw line segments between neighboring points in different figures, as would
be the case in a rectangular parametric mesh. How is any plotting routine
going to create such line segments in any reasonable manner?

  My advice would be something along the following lines. Establish some
common parameter along all the figures such that two points with the same
parameter on adjacent figures would be reasonable neighbors of one another.
Perhaps arc length along a figure divided by its total arc length would be
appropriate, or normalized cumulative chord lengths between successive
points as an approximation to this. Then interpolate between the given
points in each figure and a set of points with a common spacing for all the
figures with respect to this parameter. These new interpolated points would
have the same count on each figure and could then be used as the
appropriate mesh input to 'surf'.

Roger Stafford

Subject: problem with 3d solid

From: misty m.

Date: 15 May, 2008 08:49:02

Message: 5 of 5

but maybe easier will be to use 'cylinder'? now i tried
only for one circle:
i have my (x,y) and distance between them z=1. so, by using
[x,y,z]=cylinder
surf(x,y,z)
i should get a cylinder in coefficients in x,y and
height=1.. but i get default matlab-cylinder.

by:
[x,y,z]=cylinder(sqrt(x.^2 +y.^2))
surf(x,y,z)

i get something looking as vase..

do You know what i do wrong?

kind regards,
  misty

Tags for this Thread

No tags are associated with 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