Trying to define a circle within a matrix

8 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Cartesian Coordinate System Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by