convert 2D polar plot into 3D balloon
Show older comments
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
on 9 Nov 2015
1 vote
The File Exchange has several 3D polar plot contributions. See the search on polar 3D for 54 of them.
6 Comments
Mark Thompson
on 10 Nov 2015
Star Strider
on 10 Nov 2015
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.
Mark Thompson
on 10 Nov 2015
Star Strider
on 10 Nov 2015
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
Mark Thompson
on 12 Nov 2015
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.
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!