필터 지우기
필터 지우기

How to plot circle by one single equation?

조회 수: 167 (최근 30일)
Ameer Hamza
Ameer Hamza 2018년 5월 13일
댓글: krishan Gopal 2021년 12월 9일
I need code which plot the circle in one single equation (variable). I have the code but i need code of single equation, the code which i have, it is composed of two equations as follow :
r=2;
x=0;
y=0;
th = 0:pi/6:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
plot(xunit, yunit);

채택된 답변

John D'Errico
John D'Errico 2018년 5월 13일
편집: John D'Errico 2018년 5월 13일
As one "equation" what does that mean? About the best I can offer is this:
r=2;
x0=0;
y0=0;
ezplot(@(x,y) (x-x0).^2 + (y-y0).^2 -r^2)
axis equal
Be careful that the units are equal for the two axes, else it ill not look circular.
I could also have done it using fimplicit.
r=2;
x0=0;
y0=0;
syms x y
fimplicit((x-x0).^2 + (y-y0).^2 -r^2)
axis equal
So, in either case, only one equation.
If you really insist on only one "variable, then you need to use a polar coordinate transformation. Thus, you can do it in terms of polar angle theta, as:
r=2;
x0=0;
y0=0;
theta = linspace(0,2*pi,100);
plot(x0 + r*cos(theta),y0 + r*sin(theta),'-')
axis equal
So only one variable, theta. If you are hoping for something else, something more or less, then you need to explain carefully what the goal is here.
Are you looking for a simple way to plot a circle? Perhaps try this:
cplot = @(r,x0,y0) plot(x0 + r*cos(linspace(0,2*pi)),y0 + r*sin(linspace(0,2*pi)),'-')
Now you have a little function that will plot a circle.
cplot(2,0,0)
hold on
cplot(3,1,2)
cplot(1,-1,1)
axis equal
  댓글 수: 2
Abdulrahman Saad
Abdulrahman Saad 2019년 10월 5일
Thank you very much
krishan Gopal
krishan Gopal 2021년 12월 9일
Hi, can you tell me how to draw line pattern inside the circle

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Aditya Gupta
Aditya Gupta 2020년 6월 26일
Adding to the MVP's (perfect) answer, I found one more way:
radius = 2;
originX = 0;
originY = 0;
rectangle('Position',[originX-radius originY-radius 2*radius 2*radius], ...
'Curvature',[1 1]);
axis equal

Harshith pothuri
Harshith pothuri 2021년 1월 14일
r=2;
x0=0;
y0=0;
theta = linspace(0,2*pi,100);
plot(x0 + r*cos(theta),y0 + r*sin(theta),'-')
axis equal

krishan Gopal
krishan Gopal 2021년 12월 9일
Hi, can you tell me how to draw line pattern inside the circle

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by