How to create a FILLED circle within a matrix

51 ビュー (過去 30 日間)
Edward Villanueva
Edward Villanueva 2019 年 12 月 7 日
コメント済み: Image Analyst 2019 年 12 月 7 日
this is my code thus far, it is used to create two circles within a matrix and then calculate the values of these circle accordingly. My issue is that I need the circles to be filled, I am not sure how to modify my code to do this. I had previous help implementing the circles but I cannot get the circle to be filled as I need it to be.
cx1 = -.05; %x position of circle
cy1 = 0; %y position of circle
cr1 = .04; %radius of circle
th = 0:pi/500:2*pi;
xunit = cr1 * cos(th) + cx1;
yunit = cr1 * sin(th) + cy1;
%%%%%%%%%
cx2 = .03; %x position of circle
cy2 = 0; %y position of circle
cr2 = .02; %radius of circle
xunit2 = cr2 * cos(th) + cx2;
yunit2 = cr2 * sin(th) + cy2;
%%%%%%
x= -.1:.001: .1;
[X,Y]=meshgrid(x); % xy space
v1=zeros(size(X)); % previous v
xidx = interp1(x, 1:length(x), xunit, 'nearest');
yidx = interp1(x, 1:length(x), yunit, 'nearest');
xidx2 = interp1(x, 1:length(x), xunit2, 'nearest');
yidx2 = interp1(x, 1:length(x), yunit2, 'nearest');
idx = sub2ind(size(X), yidx, xidx);
idx2 = sub2ind(size(X), yidx2, xidx2);
v1(idx) = 10;
v1(idx2) = 3;
v2=v1; % next v
figure;
for n=1:100 %number of iterations
for i=2:length(X(1,:))-1 %not disturbing the boundaries
for j=2:length(Y(1,:))-1
v2(i,j)=1/4*(v1(i+1,j)+v1(i-1,j)+v1(i,j-1)+v1(i,j+1));
end
end
v1=v2; %update v1 for next iteration
end
pcolor(x,x,v1); colormap jet; colorbar; shading interp;
axis square;
title(["voltage"]);
drawnow;
axis tight;

回答 (1 件)

Image Analyst
Image Analyst 2019 年 12 月 7 日
  2 件のコメント
Edward Villanueva
Edward Villanueva 2019 年 12 月 7 日
Not exactly what im looking for, I already have a circle made within the matrix, I just need to figure a way out to get that circle filled instead of only having the parimeter
Image Analyst
Image Analyst 2019 年 12 月 7 日
You must have used the wrong FAQ code. use the first code sample:
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 201;
imageSizeY = 201;
[columnsInImage, rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = imageSizeX / 2; % Wherever you want.
centerY = imageSizeY / 2;
radius = 50;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
image(circlePixels) ;
colormap([0 0 0; 1 1 1]);
title('Binary image of a circle');
axis square;
0000 Screenshot.png
As you can see, the circle is solid, not just a perimeter. Adapt as needed.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRed についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by