Explanation on how to make a circle

2 ビュー (過去 30 日間)
Kash Costello
Kash Costello 2018 年 10 月 31 日
編集済み: dpb 2018 年 10 月 31 日
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 320;
centerY = 240;
radius = 100;
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');
Can someone just explain to me this part:
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
I just want to further understand the whole code. If it's not too much, explanation of the whole code will be more appreciated. Thanks a lot!
  3 件のコメント
Kash Costello
Kash Costello 2018 年 10 月 31 日
Hi there! But this this part: (rowsInImage - centerY).^2? Or the other one for X? Why is it this way?
dpb
dpb 2018 年 10 月 31 日
編集済み: dpb 2018 年 10 月 31 日
How do you calculate the radius of a circle with pencil and paper?
Or, more directly, what's the distance to a point from it's origin given x,y coordinates for the point?

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by