# correct conversation from polar to cartesian coordinates for a surface profile

4 visualizzazioni (ultimi 30 giorni)
Jessica Winkler il 28 Nov 2023
Commentato: William Rose il 29 Nov 2023
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

William Rose il 28 Nov 2023
Modificato: William Rose il 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.
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Jessica Winkler il 28 Nov 2023
Modificato: Jessica Winkler il 28 Nov 2023

Wow, thank you, awesome. Yes, there is an actual discontinuity along the negative x-Axis, while there is none within the teardrop. The only thing I can’t do is having a different number of pixels in x and y, because in reality 2 of those profiles (the original and it’s negative) will be overlapped and rotated towards each other. (Combined, this results in the phase profile of a sector-lens with 2 different focal lengths that depend on their mutual rotation angle theta).

William Rose il 29 Nov 2023

Accedi per commentare.

### Categorie

Scopri di più su Heat Transfer in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by