You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Revolving a 2D plot around its vertical axis to generate 3D surface
5 views (last 30 days)
Show older comments
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 Comments
Asser Abdelgawad
on 13 Jun 2022
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
Accepted Answer
Matt J
on 13 Jun 2022
18 Comments
Matt J
on 13 Jun 2022
Edited: Matt J
on 13 Jun 2022
From your comment in the other 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;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1031310/image.png)
Asser Abdelgawad
on 14 Jun 2022
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?
Asser Abdelgawad
on 14 Jun 2022
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
on 14 Jun 2022
Edited: Matt J
on 14 Jun 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.
Asser Abdelgawad
on 14 Jun 2022
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?
Asser Abdelgawad
on 14 Jun 2022
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?
Matt J
on 14 Jun 2022
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;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1032695/image.png)
Asser Abdelgawad
on 14 Jun 2022
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
Matt J
on 14 Jun 2022
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;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1032740/image.png)
Asser Abdelgawad
on 16 Jun 2022
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.
Matt J
on 16 Jun 2022
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.
Asser Abdelgawad
on 16 Jun 2022
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.
Asser Abdelgawad
on 16 Jun 2022
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?
More Answers (0)
See Also
Categories
Find more on Logical 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)