correct conversation from polar to cartesian coordinates for a surface profile
5 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I have following problem. Within a bigger project I use the function . It describes the profile of an optical element and plotted this function should look like the gray image below. I wanted to recreate this image using cartesian coordinates (code below) and ended up with what you can see in the colored image. When you look along the positive x-axis in my plot you can see a discontinuity, which should not happen due to the 2pi-priodicity, such that as it is in the gray image.
How can I solve this problem? Thanks ahead ;)
The code i tried to use:
clc; close all; clear all;
% Variables
lam = 633e-9; % wavelength
f = 2; % focal length
a = pi/(lam*f); % Tuning constant
cutoff = 2*pi; % cutoff modulo operation
num_points = 1000; % number of pixel
% x,y-Grid
x_values = linspace(-5e-3, 5e-3, num_points); % for DOE with 1cm diameter
y_values = linspace(-5e-3, 5e-3, num_points);
[x, y] = meshgrid(x_values, y_values);
profile = a * (x.^2 + y.^2) .* atan2(y, x); % general phase profile in cartesian coords of Phi(r,phi)=a*r^2*phi
DOE_phaseprofile = mod(profile,cutoff); % DOE phaseprofile
% Plots
figure()
imagesc(x_values, y_values, DOE_phaseprofile);
colorbar;
xlabel('x (m)');
ylabel('y (m)');
viscircles([0 0],5e-3, 'LineWidth',0.8);
axis equal;
title('DOE1 PhaseProfil');
0 个评论
回答(1 个)
William Rose
2023-11-28
编辑:William Rose
2023-11-28
[edit: clean up copy-paste error, remove a line of code I added that was superfluous]
[edit: Reverse the axis labels. I rotated the plot 90 deg, but forgot to flip the axis labels.]
% Variables
lam = 633e-9; % wavelength
f = 2; % focal length
a = pi/(lam*f); % Tuning constant
cutoff = 2*pi; % cutoff modulo operation
num_points = 1000; % number of pixel
% x,y-Grid
x_values = linspace(-5e-3, 5e-3, num_points); % for DOE with 1cm diameter
y_values = linspace(-5e-3, 5e-3, num_points);
[x, y] = meshgrid(x_values, y_values);
profile = a * (x.^2 + y.^2) .* atan2(y, x); % general phase profile in cartesian coords of Phi(r,phi)=a*r^2*phi
DOE_phaseprofile = mod(profile,cutoff); % DOE phaseprofile
DOE_phaseprofile(y>0)=2*pi-DOE_phaseprofile(y>0);
% Plots
figure()
imagesc(y_values, x_values, DOE_phaseprofile');
colorbar;
xlabel('y (m)');
ylabel('x (m)');
viscircles([0 0],5e-3, 'LineWidth',0.8);
axis equal;
title('DOE1 PhaseProfil');
Try it. Good luck.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!