Draw a Circle in Matlab Fill Color

Matlab Plot Circle

Introduction to Matlab Plot Circle

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

How to Create a circumvolve using Rectangle Function?

Let united states of america outset acquire syntax to depict a elementary circumvolve in MATLAB:

1. Let united states outset declare some points, here we are taking 500 points. The beneath code will create these points.

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

2. Permit the states now declare the radius and centre of the circle. The center will be divers past x and y co-ordinates.

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

iii. Finally, we will plot our circle.

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

4. Nosotros volition also write some code for our output to look visually better. This is normal formatting and nosotros can adjust it as per our requirement.

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

5. This is how our input and output will await like in MATLAB console:

Lawmaking:

angles = linspace(0, 2*pi, 500);
radius = 20;
CenterX = 50;
CenterY = forty;
x = radius * cos(angles) + CenterX;
y = radius * sin(angles) + CenterY;
plot(x, y, 'b-', 'LineWidth', 2);
concur on;
plot(CenterX, CenterY, 'thou+', 'LineWidth', 3, 'MarkerSize', 14);
grid on;
centrality equal;
xlabel('10', 'FontSize', fourteen);
ylabel('Y', 'FontSize', 14);

Output:

Matlab Plot Circle - 1

As we can come across in the to a higher place output, the circle is created with a radius 20 and centre (50, twoscore) every bit defined by us in the code.

How to Create a Solid 2nd Circle in MATLAB?

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

1. First, we will be creating logical image of circle. For this, we will ascertain centre, diameter and the image size. Let us first create epitome.

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

2. Next, nosotros will be creating the circle inside the image.

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

3. In the in a higher place line of code, Pixels is "logical" array and is 2d. Let us now brandish 'Pixels'.

  • prototype(Pixels);
  • colormap([0 0 0; 1 i 1]);
  • title('Image of circle');

iv. This is how our input and output volition look similar in MATLAB panel:

Code:

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

Output:

Matlab Plot Circle - 2

How to create a Circle in MATLAB Using Rectangle Function?

Let us now acquire how to create a circle in MATLAB using rectangle role: Here is a simple code to achieve this:

ane. Similar nosotros discussed in to a higher place examples, nosotros volition declare the radius and center co-ordinates of the required circle.

  • radius = half-dozen;
  • centerX = thirty;
  • centerY = 40;
  • rectangle('Position',[centerX – radius, centerY – radius, radius*ii, radius*2],…
  • 'Curvature',[1,1],…
  • 'FaceColor','b');
  • axis square;

2. We have passed 'FaceColor' as "b" and so our output circle will be of Blue colour.

Code:

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

Output:

Rectangle Function

How we can Create a Uncomplicated arc in MATLAB?

Finally, let united states of america talk over how we can create a simple arc in MATLAB. Every bit we know that arc is nothing but a small portion of the circumvolve, lawmaking for creating an arc is also very similar to that of creating a circle.

i. First we define the parameters of required arc.

  • xCenter = 1;
  • yCenter = 1;
  • radius = 4;

2. Next, we ascertain the bending theta every bit required.

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

3. Finally, nosotros plot our defined points.

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

Code:

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

Output:

Simple arc

Determination

And then, in this article, we learnt how to create circles in MATLAB. We can create both plane circles and solid circles in MATLAB. We besides learnt how we can leverage the Rectangle function to plot circles in MATLAB. Nosotros can also format our circle equally per our requirement.

Recommended Articles

This is a guide to Matlab Plot Circle. Here we discuss an introduction, how to Create a circumvolve using rectangle function, a Solid second Circumvolve, a circle in MATLAB and Simple arc. You can also get through our other related articles to acquire more –

  1. Interruption 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

spainsheophy.blogspot.com

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

0 Response to "Draw a Circle in Matlab Fill Color"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel