Revolving a 2D plot around its vertical axis to generate 3D surface

While this solution is helpful, the usage of repmat makes it so that the values are repeated and not unique. What I would like to do is convert to polar and rotate without repeating values. Is there a way to execute the revolution without repmat?

2 Commenti

SAA
SAA il 13 Giu 2022
Modificato: SAA il 13 Giu 2022
cart2pol would transform to polar from cartesian.
Hmm but is there a way to do it besides repmat? For instance:
theta = linspace(0, 2*pi, 100);
for i=1:100
theta=pi/180*theta(i);
t_theta=X.*cos(theta)+Y.*sin(theta);
vals=interp1(x , y, t_theta(:),'pchip');
end

Accedi per commentare.

 Risposta accettata

18 Commenti

Hi @Matt J this is the same answer I referred to in the hyperlink of the original post.
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.
t = linspace(0,1,1000);
r=2*sqrt(-log(t));
[X,Z,Y] = cylinder(r,1000);
surf(X,Y,Z,'EdgeColor','none');
set(gca,'YDir','reverse');
xlabel X; ylabel Y; zlabel Z;
Thank you @Matt J, I appreciate your help. However, my starting function is a Gaussian with the form:
y = e^(-x^2). I don't think it's suitable to use another function because the values aren't the same, though the shape ultimately is. Is there a different approach?
Matt J
Matt J il 14 Giu 2022
Modificato: Matt J il 14 Giu 2022
What I've given you is a Gaussian profile. You're thinking in terms of the forward function y=f( r ) = e^(-r^2), but the cylinder() function needs to be given the inverse function r=f^-1( y )=2*sqrt(-log(y)).
Ah @Matt J, that makes sense! The problem is, in general, this wouldn't work because the sqrt() gives complex results for inputs outside (0,1), which wouldn't work for surf(), right? At least this is the issue I am facing currently.
Matt J
Matt J il 14 Giu 2022
Modificato: Matt J il 14 Giu 2022
this wouldn't work because the sqrt() gives complex results for inputs outside (0,1),
For z<0, sqrt(z) will give complex numbers, but you shouldn't ever need to evaluate in that range. You should only need to evaluate for z in the range of values that the Gaussian lobe can take.
Sorry what does that mean exactly? In my case, for instance, I have input values from [-300,300] let's say. They are perfectly valid input values for the standard gaussia lobe because it is defined for all x inR. This wouldn't work, correct?
Matt J
Matt J il 14 Giu 2022
Modificato: Matt J il 14 Giu 2022
The domain of the Gaussian lobe isn't prevented from taking negative values in what I've shown you. As you can see in my surface plot, the domain of the lobe runs from -6 to 6 with respect to both x and z.
I'm still not sure what you mean. If you were to do: linespace(0,2,1000), the whole thing falls apart because complex numbers are introduced. In my case, for instance:
f = fit(x, y, 'gauss1');
vals = coeffvalues(f);
x0 = x; %where x ranges randomly from -300 to 300, so it is outside the interval (0,1)
y0 = vals(3)*sqrt(-log(x0/vals(1))) + vals(2); %inverse of gaussian f
[x,z,y] = cylinder(y0,100);
surf(x,y,z) %here i get an error about complex numbers
Am I doing something wrong here? Or does the method indeed fall apart?
r=linspace(-300,300,100)';
y=4*exp(-(r/30).^2);
f = fit(r, y, 'gauss1','Lower',[0,0,0],'Upper',[inf,0,inf]);
vals = num2cell(coeffvalues(f));
[a,b,c]=deal(vals{:})
a = 4.0000
b = 0
c = 30.0000
y0=linspace(0,a,1000);
r0 = c*sqrt(-log(y0/a)); %inverse of gaussian f
[X,Z,Y] = cylinder(r0,1000);
surf(X,Y,Z,'EdgeColor','none');
set(gca,'YDir','reverse');
xlabel X; ylabel Y; zlabel Z;
Hi @Matt J. I truly appreciate your help throughout this process. However, this method doesn't create the full rotation as needed. If you look at my earlier comments, given that the x-values range from [-300, 300], the x and z values should do so as well (see the two graphs I posted). This isn't the case here. I've also attached my dataset here. Ideally, there would be two axes taking the values of "freq" and the vertical axis taking the values of "MTF_fit" accordingly
Your .mat attachment contains a million variables. I can't decipher what everything means there.
In any case, you can make the range of the plot extend out to 300 if you wish. I now show this below. However, I don't see why, just because you have data at a radius of 300, you would require the fit to be plotted there as well. A Gaussian lobe at a radius of more than 4 standard deviations is essentially zero, and is not very informative.
r=linspace(-300,300,100)';
y=4*exp(-(r/30).^2);
f = fit(r, y, 'gauss1','Lower',[0,0,0],'Upper',[inf,0,inf]);
vals = num2cell(coeffvalues(f));
[a,b,c]=deal(vals{:})
a = 4.0000
b = 0
c = 30.0000
y0=linspace(f(300),a,1000);
r0 = c*sqrt(-log(y0/a)); %inverse of gaussian f
[X,Z,Y] = cylinder(r0,1000);
surf(X,Y,Z,'EdgeColor','none');
set(gca,'YDir','reverse');
xlabel X; ylabel Y; zlabel Z;
Hi @Matt J. Thank you, this is exactly the shape I was looking for. The values in the y-axis are unfortunately repeated across the rows still, which makes for a 1D gaussian instead of the desired wider-base 2D gaussian when I perform ifft2() on this shape. This is my error when I first asked the question, as I thought cylinder() would achieve something different from repmat, but I was mistaken. Either way, thank you for your help. I will look into another method.
It doesn't really make sense to use ifft on a Gaussian. The (inverse) Fourier Transform of a Gaussian has a closed form analytical solution.
From my understanding, it is standard practice for my image processing application, which is performing the inverse FFT on the modulation transfer function in 2D (MTF2) which then gives the Point Spread Function for the imaging system.
See 2.2: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6287927/ am I perhaps understanding it wrong?
Matt J
Matt J il 16 Giu 2022
Modificato: Matt J il 16 Giu 2022
But you understand that the IFFT is just a tool meant for approximately computing the continuous inverse Fourier transform, right? Why would you need the IFFT when the exact inverse transform can be obtained analytically?
So the IFFT function yields different results than the analytical inverse fourier transform? I did know that to be honest. OK, so you're saying I'm better off coding the transform function from scratch, with the integral and all?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Centro assistenza e File Exchange

Prodotti

Release

R2021b

Richiesto:

il 13 Giu 2022

Commentato:

il 16 Giu 2022

Community Treasure Hunt

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

Start Hunting!

Translated by