correct conversation from polar to cartesian coordinates for a surface profile
3 views (last 30 days)
Show older comments
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.
. 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 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 Comments
Answers (1)
William Rose
on 28 Nov 2023
Edited: William Rose
on 28 Nov 2023
[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.
See Also
Categories
Find more on Orange 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!

