# Mesh grid to deal with cartesian and cylindrical coordinates

**URL:** https://community.freefem.org/t/mesh-grid-to-deal-with-cartesian-and-cylindrical-coordinates/3392
**Category:** General Discussion
**Created:** [July 11, 2024, 2:20pm UTC](https://community.freefem.org/t/mesh-grid-to-deal-with-cartesian-and-cylindrical-coordinates/3392 "2024-07-11T14:20:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![idk2020](https://avatars.discourse-cdn.com/v4/letter/i/4bbf92/32.png) [@idk2020](https://community.freefem.org/u/idk2020)
#### Post date: [July 11, 2024, 2:20pm UTC](https://community.freefem.org/t/mesh-grid-to-deal-with-cartesian-and-cylindrical-coordinates/3392/1 "2024-07-11T14:20:16Z")

</div>

I want to convert the following code into Freefem++, but I am not sure how to deal with the theta variable in case i choose a square mesh and periodic boundary conditions.  
k = 2;  
a = 4;  
gaussian\_like\_tanh = @(x) tanh(k \* (x + a)) - tanh(k \* (x - a));  
theta = linspace(0, 2_pi, 1000); % Angular coordinate  
x = linspace(-10, +10, 1000); % Radial coordinate  
[Theta, X] = meshgrid(theta, x);  
Z = gaussian\_like\_tanh(X);  
% Convert cylindrical coordinates to Cartesian coordinates  
R = X;  
X = R ._ cos(Theta);  
Y = R .\* sin(Theta);

% Plot the surface  
figure(7)  
surf(X,Y,Z); shading interp;
