Your code is going to loop through all the co-ordinates (x,y) / points and wherever the point lies on the circle, energize it.
The distance from the center of a circle between the center point (h, k) and the point on the circle (x, y), where the radius is represented by "r": √((x - h)² + (y - k)²) ) From Pythagoras theorem. I ran the code below in Matlab.
% Define the grid size
grid_rows = 10; % Example size, adjust as needed
grid_cols = 10; % Example size, adjust as needed
% Define the center of the grid
midrow = grid_rows / 2;
midcol = grid_cols / 2;
% Define the radius of the circle
radius2 = 4; % Updated radius
% Create a grid with the same size as your existing grid
volt_grid = zeros(grid_rows, grid_cols);
% Draw the circle (for visualization)
rectangle('Position', [midrow-radius2, midcol-radius2, radius2*2, radius2*2], 'Curvature', [1, 1]);
% Loop through the grid to assign 1 volt to the boundary of the circle
for i = 1:grid_rows
for j = 1:grid_cols
% Calculate the distance from the center of the circle
dist = sqrt((i - midrow)^2 + (j - midcol)^2);
% Check if the point is on the boundary of the circle
if abs(dist - radius2) < 0.5 % Allowing a small margin for boundary points
volt_grid(i, j) = 1; % Assign 1 volt
end
end
end
% Display the grid with voltages
imagesc(volt_grid);
colorbar;
title('Voltage Distribution on Circle Boundary');