# Trying to define a circle within a matrix

2 views (last 30 days)
Jasmine Penney on 26 Sep 2022
Answered: RITAM BASU on 26 Sep 2022
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!

KSSV on 26 Sep 2022
[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 on 26 Sep 2022
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