How to make circle in matrix form

16 visualizaciones (últimos 30 días)
Milou Wimart-Clifford
Milou Wimart-Clifford el 10 de En. de 2022
Respondida: Image Analyst el 10 de En. de 2022
Hi guys,
is it possible to draw a circle in matrix form on matlab?
thanks!

Respuestas (3)

Star Strider
Star Strider el 10 de En. de 2022
I am not certain what th desired result is.
This is the best I can do —
k = 10;
M = zeros(k);
v = 0:0.2:k-2;
x = ceil(k/2+k/2*cos(2*pi*v/max(v)));
x(x==0) = 1;
y = ceil(k/2+k/2*sin(2*pi*v/max(v)));
y(y==0) = 1;
ix = sub2ind(size(M), x, y);
M(ix) = 1
M = 10×10
0 0 1 1 1 1 1 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1 1 0 0
figure
spy(M)
grid
.

Simon Chan
Simon Chan el 10 de En. de 2022
Another option using function pol2cart:
clear; clc;
separation = 1; % Angle separation, 1 degree
rho = 15; % Radius, 15 pixels
num_dot = 360/separation +1; % Total number of points
theta = linspace(-pi,pi,num_dot); % Theta separation
cx = 50; % Your center point, x-coordinates = 50 (example)
cy = 25; % Your center point, y-coordinates = 25 (example)
[xA,yA] = pol2cart(theta,rho); % Use pol2cart
A = zeros(100,100); % Original region, example, size: 100x100
[Ny, Nx]= size(A);
xA_convert = round(cx-xA); % Convert back from polar coordinates
yA_convert = round(cy-yA);
for k = 1:num_dot
A(yA_convert(k),xA_convert(k)) =1; % Put the dots in matrix A
end
figure(1)
plot(cx,cy,'ro'); % Your center point
hold on
plot(xA_convert,yA_convert,'b+')
xlim([0 Nx])
ylim([0 Ny])
figure(2)
imshow(A)
Results:
Showing Matrix A using function imshow:

Image Analyst
Image Analyst el 10 de En. de 2022

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by