how can I draw half circle in matlab ?

63 views (last 30 days)
Lee
Lee on 20 Sep 2020
Edited: Lee on 21 Sep 2020
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....

Accepted Answer

John D'Errico
John D'Errico on 20 Sep 2020
Edited: John D'Errico on 20 Sep 2020
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 Comments
John D'Errico
John D'Errico on 20 Sep 2020
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 on 21 Sep 2020
Edited: Lee on 21 Sep 2020
It's too hard ;-(
But I appreciate you.
Thank you so much. Have a nice day :)~

Sign in to comment.

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!