Hello Madheswaran
Thank you so much, I really appreciate your help.
The following code allows me to calculate the target density in the circles and in the flat section (rectangle), but I also have the density in the arcs. I added a for condition to my script to account for the arcs (I wrote the functions in separate .m files). unfortunetaly I couldn't obtain the desired profile.
P.S: Using the code you provided, we can only add the arcs to my original target, the goaI is to have the entire profil.
Thank you .
% Define parameters
targ_rod_thickness = 0.6; % Thickness of the flat section in microns
targ_length = 25; % Total length of the target in microns
targ_ball_radius = 2; % Radius of the spherical balls in microns
critical_density = 1.73e27; % Critical density per m3
targ_dens = 30 * critical_density; % Density value for Hydrogen target
curvature = 1; % The expo region
% ############### Grid resolution ###############
dx = 0.05; % Resolution
x = -5:dx:targ_length + 5; % Positive x-coordinates
y = -4 * targ_rod_thickness:dx: 4 * targ_rod_thickness; % y-coordinates for thickness range
[X, Y] = meshgrid(x, y); % A 2D grid of coordinates
% ############# Initialize density matrix #############
density = zeros(size(X));
% Density for Flat Section (Central Rod)
for i = 1:numel(X)
if (Y(i) >= -targ_rod_thickness) && (Y(i) <= targ_rod_thickness) && ...
(X(i) >= targ_ball_radius) && (X(i) <= targ_length - targ_ball_radius)
density(i) = targ_dens; % Set density for the rod region
else
density(i) = 0; % Otherwise, keep density as 0
end
end
% ################### Density for Circular Ends ####################
% % Right end circle
ball_right_condition = ((X - (targ_length - targ_ball_radius)).^2 + Y.^2 <= targ_ball_radius^2);
density(ball_right_condition) = targ_dens;
% % Left end circle
ball_left_condition = ((X - targ_ball_radius).^2 + Y.^2 <= targ_ball_radius^2);
density(ball_left_condition) = targ_dens;
% ################### Density for the Arc Transition #####################
% Define arc parameters
[xtop, ytop] = topArc([2.8;1.8], [8; 1], 15); % Top arc
[xbot, ybot] = bottomArc([8; -1], [2.8; -1.8], 15); % Bottom arc
% Arc density for Top and Bottom Arcs
for i = 1:numel(X)
for j = 1:numel(Y)
% Distance to top arc
dist_top = sqrt((X(i) - xtop).^2 + (Y(i) - ytop).^2);
% Distance to bottom arc
dist_bot = sqrt((X(i) - xbot).^2 + (Y(i) - ybot).^2);
% If the point is close to the arcs (within a small threshold), apply density
if min(dist_top) < 0.1 || min(dist_bot) < 0.1
density(i, j) = targ_dens; % Assign density for arc regions
end
end
end
% ################### Plot the Target #####################
figure;
contourf(X, Y, density, 'LineColor', 'none'); % Filled contour plot
colormap([1 1 1; 0 0 1]); % White for 0, blue for density
axis equal;
xlabel('X (µm)');
ylabel('Y (µm)');
title('Gas Jet Target with Density on Arcs');