Thread Subject: 3d From 2d

Subject: 3d From 2d

From: Alex Johns

Date: 16 Mar, 2010 00:03:05

Message: 1 of 7

Hi all. So I'm trying to create a very specific 3d graph. I am starting with a "curve" (it's actually a set of line segments) in an x-y plane and I need to rotate the entire graph around the y (vertical) axis to create a 3d graph using cylindrical coordinates. Is there any way in matlab to rotate a 2d graph about an axis to create a 3d graph?

Thanks for all the help.

Alex

Subject: 3d From 2d

From: Darren Rowland

Date: 16 Mar, 2010 05:19:03

Message: 2 of 7

You probably need to provide some more information.
Do you have a formula for determining how far into the z-direction each line segment should go?

Subject: 3d From 2d

From: Walter Roberson

Date: 16 Mar, 2010 19:43:09

Message: 3 of 7

Alex Johns wrote:
> Hi all. So I'm trying to create a very specific 3d graph. I am
> starting with a "curve" (it's actually a set of line segments) in an x-y
> plane and I need to rotate the entire graph around the y (vertical) axis
> to create a 3d graph using cylindrical coordinates. Is there any way in
> matlab to rotate a 2d graph about an axis to create a 3d graph?

See my reply a moment ago to Richard's topic "Spin a 2D Trace into a 3D Graph"

Subject: 3d From 2d

From: Alex Johns

Date: 17 Mar, 2010 03:12:05

Message: 4 of 7

"Darren Rowland" <darrenjremovethisrowland@hotmail.com> wrote in message <hnn4c7$p9i$1@fred.mathworks.com>...
> You probably need to provide some more information.
> Do you have a formula for determining how far into the z-direction each line segment should go?

Hmm... Well what I have is a set of x-y coordinate pairs in an array. I generate the 2d graph simply by connecting point i to point i+1. So my 2d graph is just a series of connected lines. I need to rotate the entire graph by 2pi about the y-axis. So each line segment will generate a hollow cone segment. In cylindrical coordinates, each x-y pair becomes an r-y pair for all theta in [0, 2pi].

I'm not sure if this is the information you are looking for. Let me know if it's still confusing.

Alex

Subject: 3d From 2d

From: Walter Roberson

Date: 17 Mar, 2010 07:37:24

Message: 5 of 7

Alex Johns wrote:

> Hmm... Well what I have is a set of x-y coordinate pairs in an array. I
> generate the 2d graph simply by connecting point i to point i+1. So my
> 2d graph is just a series of connected lines. I need to rotate the
> entire graph by 2pi about the y-axis. So each line segment will
> generate a hollow cone segment. In cylindrical coordinates, each x-y
> pair becomes an r-y pair for all theta in [0, 2pi].

R = sqrt(X.^2+Y.^2);

Now generate circles of radius R (a vector), with the K'th circle having
a constant Y coordinate equal to Y(K) and being in the X-Z plane with
radius R(K).

If you approximate the circle by an N-gon, then you can pre-calculate
the vertices of the N-gon with unit "radius", and then just multiply
those vertex coordinates by R(i) to get the new X,Z coordinates.
If you think about it that way, then you can vectorize the entire
calculation. You'll probably want to draw both the circles and the
connecting edges -- easy enough to do once you have calculated all of
the coordinates into a simple array.

Subject: 3d From 2d

From: Darren Rowland

Date: 17 Mar, 2010 08:13:08

Message: 6 of 7

Alex,
This may be what you're after

% Some random data
x = 0.1:0.1:1;
y = sort(rand(1,10));

% Number of radial spokes
n = 21;

% Transform data for cylindrical presentation
theta = linspace(0,2*pi,n);

xr = x.'*cos(theta);
zr = x.'*sin(theta);
yr = repmat(y.',1,n);

surf(xr,zr,yr)

Hth
Darren

Subject: 3d From 2d

From: Alex Johns

Date: 17 Mar, 2010 15:51:25

Message: 7 of 7

"Darren Rowland" <darrenjremovethisrowland@hotmail.com> wrote in message <hnq2uj$b73$1@fred.mathworks.com>...
> Alex,
> This may be what you're after
>
> % Some random data
> x = 0.1:0.1:1;
> y = sort(rand(1,10));
>
> % Number of radial spokes
> n = 21;
>
> % Transform data for cylindrical presentation
> theta = linspace(0,2*pi,n);
>
> xr = x.'*cos(theta);
> zr = x.'*sin(theta);
> yr = repmat(y.',1,n);
>
> surf(xr,zr,yr)
>
> Hth
> Darren


Hi Darren. That code worked perfectly for what I wanted to do. It wasn't even very hard to implement. Thank you so much. It also looks REALLY cool

Alex

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com