Draw a Circle With Centre and Radius in Matlab

Matlab Plot Circle

Introduction to Matlab Plot Circumvolve

MATLAB can exist used to perform operations involving geometric figures similar circles, rectangles, squares etc. In this article, nosotros will focus on circles. We will larn how to create diverse types of circles in MATLAB. Nosotros can create solid or airplane circles in MATLAB, which we volition learn as we go alee in the article. We will also acquire how to create a circle using the rectangle function.

How to Create a circle using Rectangle Function?

Let united states first learn syntax to draw a simple circle in MATLAB:

1. Let united states of america commencement declare some points, hither we are taking 500 points. The below code will create these points.

  • angles = linspace(0, 2*pi, 500);

2. Let us now declare the radius and centre of the circumvolve. The centre volition be defined past ten and y co-ordinates.

  • radius = 20;
  • CenterX = 50;
  • CenterY = 40;

iii. Finally, we volition plot our circle.

  • x = radius * cos(angles) + CenterX;
  • y = radius * sin(angles) + CenterY;

four. Nosotros will also write some code for our output to wait visually meliorate. This is normal formatting and nosotros tin adjust it as per our requirement.

  • plot(x, y, 'b-', 'LineWidth', 2);
  • hold on;
  • plot(CenterX, CenterY, 'k+', 'LineWidth', 3, 'MarkerSize', 14);
  • grid on;
  • axis equal;
  • xlabel('X', 'FontSize', 14);
  • ylabel('Y', 'FontSize', 14);

5. This is how our input and output will look similar in MATLAB console:

Code:

angles = linspace(0, two*pi, 500);
radius = 20;
CenterX = 50;
CenterY = 40;
10 = radius * cos(angles) + CenterX;
y = radius * sin(angles) + CenterY;
plot(ten, y, 'b-', 'LineWidth', 2);
agree on;
plot(CenterX, CenterY, '1000+', 'LineWidth', 3, 'MarkerSize', 14);
grid on;
axis equal;
xlabel('X', 'FontSize', 14);
ylabel('Y', 'FontSize', 14);

Output:

Matlab Plot Circle - 1

As we tin can see in the above output, the circle is created with a radius 20 and centre (fifty, 40) as defined past us in the code.

How to Create a Solid 2D Circle in MATLAB?

Next, permit us learn how to create a solid 2D circle in MATLAB:

1. First, we will be creating logical epitome of circle. For this, we will ascertain center, diameter and the image size. Allow usa kickoff create image.

  • imageSizeOfX = 640;
  • imageSizeOfY = 480;
  • [colInImage rowsInImage] = meshgrid(ane : imageSizeOfX, 1 : imageSizeOfY);

2. Next, we will exist creating the circle inside the epitome.

  • centerOfX = 320;
  • centerOfY = 240;
  • radius = fourscore;
  • Pixels = (rowsInImage – centerOfY).^two …
  • + (colInImage – centerOfX).^ii <= radius.^two;

3. In the above line of code, Pixels is "logical" array and is second. Let us now display 'Pixels'.

  • image(Pixels);
  • colormap([0 0 0; 1 1 i]);
  • title('Image of circumvolve');

4. This is how our input and output will expect similar in MATLAB panel:

Code:

imageSizeOfX = 640;
imageSizeOfY = 480;
[colInImage rowsInImage] = meshgrid(1 : imageSizeOfX, 1 : imageSizeOfY);
centerOfX = 320;
centerOfY = 240;
radius = lxxx;
Pixels = (rowsInImage - centerOfY).^two ...
+ (colInImage - centerOfX).^2 <= radius.^2;
image(Pixels);
colormap([0 0 0; 1 1 1]);
title('Image of circle');

Output:

Matlab Plot Circle - 2

How to create a Circle in MATLAB Using Rectangle Function?

Permit us now learn how to create a circle in MATLAB using rectangle office: Here is a simple lawmaking to achieve this:

ane. Similar we discussed in above examples, we will declare the radius and centre co-ordinates of the required circumvolve.

  • radius = 6;
  • centerX = 30;
  • centerY = 40;
  • rectangle('Position',[centerX – radius, centerY – radius, radius*2, radius*2],…
  • 'Curvature',[1,1],…
  • 'FaceColor','b');
  • axis square;

ii. We take passed 'FaceColor' equally "b" so our output circle will be of Bluish colour.

Code:

radius = 6;
centerX = thirty;
centerY = forty;
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*2],...
'Curvature',[one,one],...
'FaceColor','b');
axis square;

Output:

Rectangle Function

How we can Create a Simple arc in MATLAB?

Finally, let us discuss how nosotros can create a elementary arc in MATLAB. As nosotros know that arc is nothing only a minor portion of the circle, code for creating an arc is also very like to that of creating a circle.

1. First nosotros define the parameters of required arc.

  • xCenter = 1;
  • yCenter = 1;
  • radius = iv;

2. Side by side, we define the angle theta as required.

  • theta = linspace(twenty, 100, 50);
  • x = radius * cosd(theta) + xCenter;
  • y = radius * sind(theta) + yCenter;

3. Finally, we plot our defined points.

  • plot(x, y, 'b-', 'LineWidth', 2);
  • centrality equal;
  • grid on;

Code:

xCenter = one;
yCenter = i;
radius = 4;
theta = linspace(20, 100, fifty);
x = radius * cosd(theta) + xCenter;
y = radius * sind(theta) + yCenter;
plot(x, y, 'b-', 'LineWidth', two);
axis equal;
grid on;

Output:

Simple arc

Conclusion

So, in this article, we learnt how to create circles in MATLAB. We tin can create both plane circles and solid circles in MATLAB. We also learnt how we can leverage the Rectangle function to plot circles in MATLAB. Nosotros can as well format our circumvolve as per our requirement.

Recommended Manufactures

This is a guide to Matlab Plot Circle. Hither we discuss an introduction, how to Create a circle using rectangle function, a Solid 2D Circumvolve, a circle in MATLAB and Simple arc. You lot tin can also become through our other related articles to acquire more –

  1. Pause in MATLAB
  2. Nested Loop in Matlab
  3. Matlab pcolor() | Examples
  4. Complete Guide to Optimset Matlab
  5. Plot Vector Matlab | Functions
  6. Matlab Effigy | Examples
  7. xlabel Matlab | Examples

mcalistertherited.blogspot.com

Source: https://www.educba.com/matlab-plot-circle/

0 Response to "Draw a Circle With Centre and Radius in Matlab"

ارسال یک نظر

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel