MATLAB Answers

2

How do I plot a circle with a given radius and center?

I would like to plot a circle with a given radius and center.

3 Answers

Answer by MathWorks Support Team on 3 Jan 2019 at 5:00
 Accepted Answer

Here is a MATLAB function that plots a circle with radius 'r' and locates the center at the coordinates 'x' and 'y':
function h = circle(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit, yunit);
hold off
An alternative method is to use the 'rectangle' function:
function h = circle2(x,y,r)
d = r*2;
px = x-r;
py = y-r;
h = rectangle('Position',[px py d d],'Curvature',[1,1]);
daspect([1,1,1])
If you are using version R2012a or later and have Image Processing Toolbox, then you can use the 'viscircles' function to draw circles:
viscircles(centers,radii)

  7 Comments

Thanks and we want answer to plot circle when they have given us centre and a point on the circle
If you would like to plot a circle given two points [Center, Point on circle], rather than [Center, Radius], you can simply calculate the distance between your two points, and then use that distance as the radius.

Sign in to comment.


Answer by serwan Bamerni on 17 Feb 2016

  1 Comments

This is part of the Image Processing Toolbox

Sign in to comment.


Answer by amine bouabid on 23 Jul 2018
Edited by amine bouabid on 23 Jul 2018

hello
you can plot a circle simply by writing :
syms x; syms y;
ezplot((x-xi).^2+(y-yi).^2-r.^2)
where xi and yi are the coordinates of the center and r is the radius

  0 Comments

Sign in to comment.