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

조회 수: 116 (최근 30일)
Munish Kumar
Munish Kumar 2017년 3월 3일
편집: John D'Errico 2017년 6월 28일
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
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
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

jack wu
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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by