Trying to define a circle within a matrix

9 ビュー (過去 30 日間)
Jasmine Penney
Jasmine Penney 2022 年 9 月 26 日
回答済み: RITAM BASU 2022 年 9 月 26 日
I am trying to define the points of a circle within a matrix. I have a matrix that has 50 rows and 50 columns. I want to define a circle with radius 10 anywhere in that matrix. Not sure how to start it out!

回答 (2 件)

KSSV
KSSV 2022 年 9 月 26 日
[X,Y] = meshgrid(1:50) ;
C = [mean(X(:)) mean(Y(:))] ;
R = 10 ;
th = linspace(0,2*pi) ;
x = C(1)+R*cos(th) ;
y = C(2)+R*sin(th) ;
[in,on] = inpolygon(X,Y,x,y) ;
spy(in)

RITAM BASU
RITAM BASU 2022 年 9 月 26 日
As far as I understand, you are trying to get values of some indices of the matrix, (like element (3,3)), which are equidistant from the central coordinates.
If that is the case, treat it as cartesian coordinates, where each length is 1 unit.. so if you go from (1,2) to (1,3) you go one unit. if you go from (1,2) to (2,3) you go sqrt(2) distance.
you can write a function, that calculates the indices difference of all the points of the matrix from a given center, and take only those who satisfy the condition a(2)+b(2)=10(2).. (the brackets are squares)
But I am not sure how many values you will get. Hope it helps

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by