Write a function that draws a circle on the coordinate plane.
The MATLAB function should use a,b r inputs, where a and b are the x-axis and y-axis coordinates of the center of the circle and the radius being r.
Add the labels to axes and annotation (a,b) at the center of the circle.
(use the parametric equation of a circle).
function DrawCircle(a, b, r)
%DRAWCIRCLE draws a circle on the coordinate plane
% a and b are the x-axis and y-axis coordinates of the center
% of the circle and r is its radius
t = 0:pi/180:2*pi;
x = r*cos(t) + a;
y = r*sin(t) + b;
plot(x, y, '-', a, b, '.');
axis equal
axis padded
text(a, b,'\leftarrow center')
title("The circle of radius " + string(r));
xlabel("X");
ylabel("Y")
end
Comments
Leave a comment