MATLAB Answers


How do I plot a circular arc with given two endpoints and radius?

Asked by Munish Kumar on 3 Mar 2017
Latest activity Edited by John D'Errico
on 28 Jun 2017
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 Comment

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.

Sign in to comment.

2 Answers

Answer by jack wu
on 28 Jun 2017
Edited by John D'Errico
on 28 Jun 2017

%first input
a=[0 1]; %P1
b=[1 0]; %P2
r=1; %radius
%next solution
syms 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)), ...
axis equal
ezplot((X-x(2))^2+(Y-y(2))^2==r^2,[min(a(1),b(1)),max(a(1),b(1)), ...
axis equal

  1 Comment

Repaired solution to be readable.

Sign in to comment.

Answer by Andrei Bobrov
on 28 Jun 2017

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)';
plot(r*cosd(phi) + v(1),r*sind(phi) + v(2),'-b',v(1),v(2),'ok')
grid on


Sign in to comment.