Filter löschen
Filter löschen

Trying to define a circle within a matrix

11 Ansichten (letzte 30 Tage)
Jasmine Penney
Jasmine Penney am 26 Sep. 2022
Beantwortet: RITAM BASU am 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!

Antworten (2)

KSSV
KSSV am 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
RITAM BASU am 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

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by