# how to use plot to draw a minor arc in matlab without calculating the angle range?

6 views (last 30 days)
marvellous on 15 Nov 2023
Commented: Bruno Luong on 17 Nov 2023
In a two-dimensional surface, for a circle C, if I know its center coordinates, the radius, and two point coordinates on C, then the minor arc between the two points is uniquely determined. How can I draw it using plot or other drawing commands in matlab without calculating the angle range? Or is there any easy way to calculate the angle range?

Voss on 15 Nov 2023
c = [-1,2]; % center
p = [-1,5; -3.121,-0.121]; % two points on the circle: (-1,5) and (-3.121,-0.121)
th = atan2(p(:,2)-c(2),p(:,1)-c(1)); % angles from center c to points p
if abs(diff(th)) > pi % enforce getting the minor arc:
[~,idx] = min(th); % if the angles are more than pi apart,
th(idx) = th(idx)+2*pi; % increment the smaller one by 2*pi
end
% calculate points along the arc
th = linspace(th(1),th(2),100);
x = c(1)+r*cos(th);
y = c(2)+r*sin(th);
% plot
plot(x,y)

Bruno Luong on 15 Nov 2023
Edited: Bruno Luong on 16 Nov 2023
% Generate A, B, C, C is the center and A B are two points on circle
r = rand();
C = randn(2,1);
phi1 = 2*pi*rand;
A = C + r * [cos(phi1); sin(phi1)];
phi2 = 2*pi*rand;
B = C + r * [cos(phi2); sin(phi2)];
% Compute the minor arc that link A and B
% never call trig function (or even sqrt) to compute angle
CA=A-C;
CB=B-C;
N=[CA(2);-CA(1)];
x = [CA+CB,N]\CB;
tmax=x(2);
t=linspace(0,tmax,n);
t2 = t.*t;
P=C + ((1-t2).*CA+t.*(2*N))./(1+t2); % points on arc
% Plot the arc
close all
hold on
plot(C(1),C(2),'+b','Markersize', 10);
text(A(1),A(2),'A')
text(B(1),B(2),'B')
text(C(1),C(2),'C')
plot(P(1,:),P(2,:),'r','linewidth',1)
axis equal
##### 3 CommentsShow 1 older commentHide 1 older comment
Bruno Luong on 16 Nov 2023
Edited: Bruno Luong on 16 Nov 2023
t=linspace(0,tmax,n);
(which can be big when A and B almost opposite, since tmax goes to infinity) a more carefully discretization of the arc is
resdeg = 2; % approx resolution of the arc, in degree
phimax = pi-2/(abs(tmax)+2/pi);
phi = linspace(0,phimax,n);
t = sign(tmax)*2*(1./(pi-phi)-1/pi);
Bruno Luong on 17 Nov 2023
I pack the method in a function GetPointOnArc.m
% Generate A, B, C
r = rand();
m = 3; % dimension
C = randn(m,1);
A = randn(m,1); A=C+A*r/norm(A);
B = randn(m,1); B=C+B*r/norm(B);
P = GetPointOnArc(A, B, C);
% Plot the arc
close all
hold on
if m == 2
plot(C(1),C(2),'+b','Markersize', 10);
text(A(1),A(2),'A')
text(B(1),B(2),'B')
text(C(1),C(2),'C')
plot(P(1,:),P(2,:),'.r-','linewidth',1)
axis equal
else
plot3(C(1),C(2),C(3),'+b','Markersize', 10);
text(A(1),A(2),A(3),'A')
text(B(1),B(2),B(3),'B')
text(C(1),C(2),C(3),'C')
plot3(P(1,:),P(2,:),P(3,:),'.r-','linewidth',1)
axis equal
view(3)
end

### Categories

Find more on MATLAB in Help Center and File Exchange

R2018a

### Community Treasure Hunt

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

Start Hunting!