Getting an array of points along an arc

11 次查看(过去 30 天)
How can I replicate the following code, which plots an arc given 2 endpoints and the radius, to instead output an array of points? (Which I can then plot using plot(x,y))
i.e. I want an array of points that will give me an arc, given two endpoints a and b, and a radius r.
figure;
a = [124.0102 62.2260];
b = [33.3602 77.9434];
r=250;
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
fig = 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))]);
set(fig,'color','black','LineStyle', '--','LineWidth',2)

采纳的回答

KSSV
KSSV 2021-7-27
clc; clear all ;
figure;
a = [124.0102 62.2260];
b = [33.3602 77.9434];
r=250;
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);
x = double(x) ;
y = double(y) ;
xi = linspace(b(1),a(1)) ;
yi = linspace(a(2),b(2)) ;
[X1,Y1] = meshgrid(xi,yi) ;
R = (X1-x(2)).^2+(Y1-y(2)).^2 ;
idx = abs(R-r^2)<15 ;
Xa = X1(idx) ; Ya = Y1(idx) ;
[Xa,idx] = sort(Xa) ;
Ya = Ya(idx) ;
plot(Xa,Ya,'-*b')

更多回答(1 个)

DGM
DGM 2021-7-27
编辑:DGM 2021-7-27
This is basically the same as this answer, but maybe the explanation helps a bit:
a = [124.0102 62.2260]; % endpoints [x y]
b = [33.3602 77.9434];
r = 250; % radius
npoints = 100; % number of points to draw
% Finding the coordinates of the centers of circles
p = [a(:) b(:)];
c = sym('c',[2,1],'real');
eqs = [1,1]*(p - repmat(c(:),1,2)).^2 - r^2;
[cx cy] = vpasolve(eqs,c);
C = double([cx cy]); % solutions for centers [cx(:) cy(:)]
% each set of points with distance < 2*r
% will yield two solutions for the center coordinates
% each solution describes a circle, for which there are two possible arcs
% the arc angles are conjugate and inequal; we usually want the shorter one
% draw both short arcs and their corresponding centers
for ka = 1:size(C,1)
% find the shortest arc for this solution
v = C(ka,:);
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);
%alp = sort(alp); % only matters if you care about parameter direction
% generate points
phi = linspace(alp(1),alp(2),npoints)';
x = r*cosd(phi) + v(1);
y = r*sind(phi) + v(2);
% plot the short arc and center for this solution
plot(x,y); hold on
plot(v(1),v(2),'ok');
end
grid on
axis equal

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by