How do I plot a circular arc with given two endpoints and radius?
122 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
John D'Errico
am 28 Jun. 2017
Bearbeitet: John D'Errico
am 28 Jun. 2017
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.
Antworten (2)
Andrei Bobrov
am 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
0 Kommentare
jack wu
am 28 Jun. 2017
Bearbeitet: John D'Errico
am 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
1 Kommentar
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!