Asked by Munish Kumar
on 3 Mar 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?

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

[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

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)';

figure

plot(r*cosd(phi) + v(1),r*sind(phi) + v(2),'-b',v(1),v(2),'ok')

grid on

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## John D'Errico (view profile)

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/327895-how-do-i-plot-a-circular-arc-with-given-two-endpoints-and-radius#comment_465005

Sign in to comment.