convert 2D polar plot into 3D balloon

26 views (last 30 days)
Mark Thompson
Mark Thompson on 9 Nov 2015
Commented: Star Strider on 12 Nov 2015
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)

Star Strider
Star Strider on 9 Nov 2015
The File Exchange has several 3D polar plot contributions. See the search on polar 3D for 54 of them.
  6 Comments
Mark Thompson
Mark Thompson on 12 Nov 2015
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!
Star Strider
Star Strider on 12 Nov 2015
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

Find more on Polar Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!