Revolving a curve about the y-axis to generate a 3D surface

69 views (last 30 days)
Asser Abdelgawad
Asser Abdelgawad on 11 May 2022
Commented: Asser Abdelgawad on 13 Jun 2022 at 20:36
I'm aware that the cylinder() functiond does this for revolutions about the x-axis. But is there a way to do this about the y-axis?

Accepted Answer

John D'Errico
John D'Errico on 11 May 2022
Certainly. Just write the code yourself. Seriously, it is not difficult.
Consider the function y = f(x).
f = @(x) x.*(1-x);
fplot(f,[0,1])
We want to rotate this around the Y axis.
n = 100;
theta = linspace(0,2*pi,n).';
x0 = linspace(0,1,n);
y0 = f(x0);
x = x0.*cos(theta);
z = x0.*sin(theta);
y = repmat(y0,[n,1]);
surf(x,y,z)
xlabel x
ylabel y
zlabel z
view(20,30)
So the y axis lives at (x,z) = (0,0). The curve drawn in the original figure has been rotated around the y axis, producing this sideways cup, with a cusp at the center.
  1 Comment
Asser Abdelgawad
Asser Abdelgawad on 10 Jun 2022 at 20:20
Hello @John D'Errico. Thank you for sharing this; it helped me a lot. I have a follow-up question if you don't mind:
Is there a way to revolve the graph without using repmat? The issue is, for me, since this rotation is in the fourier domain, when i perform ifft2 to get back to spatial domain, my resultant function is essentially one-dimensional because of the repeated values from repmat. I want a 3D Gaussian from performing ifft2 on the 2D MTF here, but I get this for the PSF:
Here is my code for reference:
f = fit(freq.', MTF_fit.', 'gauss2'); %gaussian function
% rotate MTF in fourier domain
n_val = 100;
x0 = freq;
y0 = f(x0).';
theta = linspace(0,2*pi,n_val).';
x = x0.*cos(theta);
y = x0.*sin(theta);
z = repmat(y0,[n_val,1]);
MTF2 = z;
PSF2 = abs(ifftshift(ifft2(MTF2)); %back to spatial domain
surf(x,y,z) %plot top right graph
surf(PSF2) %plot bottom left graph
Ideally, the values for MTF2 wouldn't be repeated across the matrix. I've also shared what MTF2 looks like currently for refernece. What do you think?

Sign in to comment.

More Answers (1)

Matt J
Matt J on 11 May 2022
Edited: Matt J on 11 May 2022
Why not just revole around whatever axis cylinder() acommodates and then use rotate?
Or, interchange the data when you plot, e.g.,
t = 0:pi/10:2*pi;
r = 2 + cos(t);
[X,Z,Y] = cylinder(r);
surf(X,Y,Z);
xlabel X; ylabel Y; zlabel Z;
  1 Comment
Asser Abdelgawad
Asser Abdelgawad on 13 Jun 2022 at 20:36
Hi @Matt J I've tried the cylinder function with all 6 possible orderings of x,y, and z but I cannot get my gaussian function to go from left to right such as in this diagram.
This was acheived with @John D'Errico's solution, though my issue is the repeated values it produces because of repmat. How would you do it with your technique on a gaussian such as this? Is it possible with cylinder()?
Thank you so much for your help.
Asser

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by