Trying to define a circle within a matrix

조회 수: 8 (최근 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 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