How do I plot a circular arc with given two endpoints and radius?
121 次查看(过去 30 天)
显示 更早的评论
I have two points P1 and P2 with coordinates (x1,y1) & (x2,y2), respectively. I need to plot a circular arc of a given radius 'r' passing through P1 and P2.
Equation of circle (x-a)^2 + (y-b)^2 = r^2 was tried which yielded a semicircle. Then I tried the parametric equation of circle x = a + r*cos(t), y = b + r*sin(t), which again yielded a complete circle.
Is there any way to draw a circular arc through P1 & P2?
1 个评论
John D'Errico
2017-6-28
编辑:John D'Errico
2017-6-28
Note that there are always two (really 4) possible arcs, as long as the radius is at least twice the distance between the two points. So the solution will not be unique. Assuming you want the smallest possible arc, that reduces it always 2 arcs if the problem is solvable at all, and the radius isfinite. If the radius approaches inf, then the two arcs both approach the straight line between the points as a limit.
回答(2 个)
Andrei Bobrov
2017-6-28
p = [4 10;7 4]; % p - this is our points p1 & p2, p =[x1,x2;y1,y2];
r = 7; % r - radius
% Finding the coordinates of the centers of circles
% xy = [x1, y1; x2, y2]
a = sym('a',[2,1],'real');
eqs = [1,1]*(p - repmat(a(:),1,2)).^2 - r^2;
sol = vpasolve(eqs,a);
ss = struct2cell(sol);
xy = double([ss{:}]);
% example: The arc of a circle with center at xy(1,:)
v = xy(1,:);
p1 = p - v(:);
alp = atand(p1(2,:)./p1(1,:));
alp = alp + 180*(p1(1,:) < 0 & p1(2,:) > 0) - 180*(p1(1,:) < 0 & p1(2,:) < 0);
asort = sort(alp);
phi = linspace(asort(1),asort(2),100)';
figure
plot(r*cosd(phi) + v(1),r*sind(phi) + v(2),'-b',v(1),v(2),'ok')
grid on
0 个评论
jack wu
2017-6-28
编辑:John D'Errico
2017-6-28
%first input
a=[0 1]; %P1
b=[1 0]; %P2
r=1; %radius
%next solution
syms x y
[x,y]=solve((x-a(1))^2+(y-a(2))^2==r^2,(x-b(1))^2+(y-b(2))^2==r^2,x,y);
%plot arc
syms X Y
ezplot((X-x(1))^2+(Y-y(1))^2==r^2,[min(a(1),b(1)),max(a(1),b(1)), ...
min(a(2),b(2)),max(a(2),b(2))])
axis equal
figure
ezplot((X-x(2))^2+(Y-y(2))^2==r^2,[min(a(1),b(1)),max(a(1),b(1)), ...
min(a(2),b(2)),max(a(2),b(2))])
axis equal
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!