how can I draw half circle in matlab ?

조회 수: 63 (최근 30일)
Lee
Lee 2020년 9월 20일
편집: Lee 2020년 9월 21일
Hi.
I want to know how to draw half circle in rectangular coordinate .
(x - a)^2 + (y - b)^2 = r^2 ( y <= - (2/3)x )
I already know that in polar coordinate . ( when I using radius, theta )
like this
------
xCenter_2 = 3/(2*sqrt(13));
yCenter_2 = -1/sqrt(13);
theta = 0-2/3 : 0.01 : pi-2/3;
radius = 0.5;
x = radius * cos(theta) + xCenter_2;
y = radius * sin(theta) + yCenter_2;
plot(x, y), hold on;
axis square;
------
Just I want to know how to draw it " NOT use radius and theta "
I tried to this one but I failed.
------
[X,Y] = meshgrid(-4:0.01:4,-4:0.01:4); % Generate domain.
Z = X.^2 + Y.^2;
contour(X,Y,Z,[1 1]);
axis square;
------
HELP ME PLEASE....

채택된 답변

John D'Errico
John D'Errico 2020년 9월 20일
편집: John D'Errico 2020년 9월 20일
Sigh. You DID make an effort. It is not even a terrible solution, though what you did will not work, since it will at best be a full circle, and even then, it will only be a polygonal solution. That is, a contour plot is just a piecwise linear approximation. Finally, you needed to force the contour plotter to plot ONLY a specific contour, not a complete contour plot.
The contour plot you have generated is that of a paraboloid of revolution. So not really a good choice, because it is still the full circle.
How would I solve this problem? I can probably think of a couple of solutions given some time, though it seems absolutely silly to not just use pollar coordinates, since that is the direct and obvious solution. But can I do it? I imagine so.
It is simple enough to plot the full circle.
xCenter_2 = 3/(2*sqrt(13));
yCenter_2 = -1/sqrt(13);
radius = 0.5;
fxy = @(x,y) (x - xCenter_2).^2 + (y - yCenter_2).^2 - radius.^2;
fimplicit(fxy)
axis equal
But then to get only a half circle will take more work. A hack like this should work.
fxy = @(x,y) (x - xCenter_2).^2 + (y - yCenter_2).^2 - radius.^2 + (y > -(2/3)*x)*1e16;
fimplicit(fxy)
axis equal
I imagine I could do better, but why?
Or, I might formulate the problem as a differential equation, then use an ODE solver like ODE23s to solve it. If we differentiate the circle equation, it reduces to
2*(x-a) + 2*(y - b)*y' = 0
Therefore we would have
y' = -(x - a)/(y - b)
Start the solver off at one end of the arc, with initial conditions set to move in the correct direction around the circle. A stiff solver will probably be necessary, due to the singularity at y == b.
Finally, I could probably create the curve as a spline. I'm sure I could find other ways to build it. But why in the name of god and little green apples is there a reason to do so?
Just use polar coordinates.
  댓글 수: 3
John D'Errico
John D'Errico 2020년 9월 20일
Oh. I thought you wanted that. :)
How about a conformal mapping, of sorts?
Given three points that would reperesent two sides of a square. You can use linear interpolation to find any point between them. Then just remap the points to lie at a uniform distance from the center of the circle. Honestly, that is just working in polar coordinates, while obfuscating the distinction.
Lee
Lee 2020년 9월 21일
편집: Lee 2020년 9월 21일
It's too hard ;-(
But I appreciate you.
Thank you so much. Have a nice day :)~

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by