convert 2D polar plot into 3D balloon

Hi there,
I currently have some code that plots a 2D polar plot in MATLAB over theta values 0 to 2*pi radians. The polar plots appear fine. I'm wondering if anyone knows a convenient method for taking this 2D polar plot and creating a 3D balloon of this pattern (i.e. about phi angle values -pi/2 to pi/2)? That is, taking the horizontal 2D pattern and copying it around the 0-degree axis to form a 3D balloon.
Any assistance would be greatly appreciated.
Regards,
Mark

Answers (1)

The File Exchange has several 3D polar plot contributions. See the search on polar 3D for 54 of them.

6 Comments

Hi Star Strider,
Thank you for the link. I had already looked there. They are some great 3D polar plotting functions, but more so for the data that has already been calculated for each observation point. What I am looking for is a specific method of being able to extend my 3D horizontal polar plot and rotate it about an axis to form a 3D mesh.
Do you have any ideas how I may approach this problem?
Here’s one idea with an arbitrary function:
N = 25; % Sphere Faces
[Xs,Ys,Zs] = sphere(N); % Create Sphere
a = linspace(0, pi, N+1); % Sizes Must Match
Zf = sin(a).*exp(-a); % Function
Zs = bsxfun(@times, Zs', Zf)'; % Create New ‘Zs’
figure(1)
surf(Xs, Ys, Zs) % Plot
grid on
figure(2)
plot(a, Zf)
grid
You’ll have to experiment to get the result you want. The function shape on the sphere is not the exact function plotted in figure(2), so you will probably have to tweak your function to make it shape the sphere exactly, or create a second function, possibly ‘pre-warping’ your existing function so it will warp the sphere correctly, or ‘re-warping’ the sphere afterwards, implementing it with another bsxfun call.
Tweaking your function with a second warping function before warping the sphere is likely easiest. I’m not certain how best to suggest you proceed with creating the warping function.
Hi Star Strider.
Thanks for taking the time to provide an alternative solution for me. I'm not sure if this is what I'm after, however I will definitely explore tweaking the warping function. I may be able to get it to work using this method.
My pleasure.
Thinking about it some more, I believe using cylinder instead of sphere is the way to go. It’s much easier, involves no warping, and produces what I consider to be the correct plot:
N = 25; % Sphere Faces
a = linspace(0, pi, N); % Sizes Must Match
Zf1 = sin(a).*exp(-a); % Function #1
Zf2 = fliplr(Zf1); % Function #2
[Xc1,Yc1,Zc1] = cylinder(Zf1,N); % Create Cylinder #1
[Xc2,Yc2,Zc2] = cylinder(Zf2,N); % Create Cylinder #1
figure(1)
subplot(2,1,1)
surf(Xc1, Yc1, Zc1) % Plot
axis equal
grid on
subplot(2,1,2)
surf(Xc2, Yc2, Zc2) % Plot
axis equal
grid on
figure(2)
plot(a, Zf1, a, Zf2)
grid
Hmmmm, in principle what you have said should work (given the nature of how MATLAB creates a cylinder), and appears to be what I need to do. However it appears to be constrained between -1 and 1 on the z-axis, which doesn't help, but I will work on this, maybe by scaling.
In the mean time I did manage to get something to work. If I create a 3D plot (plot3) of my 2D polar data in the XY plane (by setting the z dimensions to 0 initially) you can use the MATLAB function rotation(). See below for my current method:
% convert 2D polar into Cartesian coordinates first:
[x2D, y2D] = pol2cart(theta, rho);
z2D = zeros(1,361); % set z-axis vector to 0 (maintain XY plane)
hSurface2 = plot3(x2D, y2D, z2D);
direction = [0 1 0]; % just about y-axis to make it point upward along the z-axis
rotate(hSurface2,direction,-90)
% get the new X, Y, Z data points from rotated surface data
newX = hSurface2.XData;
newY = hSurface2.YData;
newZ = hSurface2.ZData;
% check the resulting polar
hSurface4 = plot3(newX, newY, newZ);
This the allows me to copy the z values for each 360-degree rotation point about the z-axis at each elevation angle, phi. Which is great.
The problem is that you have to do these rotation operations on figure data, so I have to plot the old data, hold the plot so that I can obtain the XData, YData and ZData values from the plot data and store into variables, and then I can finally kill the plot. This makes my code very inefficient. Do you perhaps know how I can do this without needing to plot first? Or should I start this as a new question?
Again, thanks for your assistance!
As always, my pleasure!
Scaling is relatively easy in the Z direction. Simply multiply the Z produced by cylinder by whatever you want to stretch or squash it vertically. Normalise your function to the normal cylinder height of 1, then stretch the cylinder. I did that here in the last bit of code, although I didn’t post the plot image.
I still have only a vague idea of what you’re doing. If you’re going to use rotate, see if the hgtransform function and its friends can work in your application. They might make your work easier.

Sign in to comment.

Categories

Asked:

on 9 Nov 2015

Commented:

on 12 Nov 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!