How to make circle in matrix form
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi guys,
is it possible to draw a circle in matrix form on matlab?
thanks!
0 commentaires
Réponses (3)
Star Strider
le 10 Jan 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
figure
spy(M)
grid
.
0 commentaires
Simon Chan
le 10 Jan 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:
0 commentaires
Voir également
Catégories
En savoir plus sur Graphics Object Programming dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!