185 views (last 30 days)

Show older comments

Roger Stafford
on 15 Nov 2017

Edited: Roger Stafford
on 15 Nov 2017

(Correction made)

Point vectors A and B must be column vectors

A = randn(2,1); % Point A to be on circle circumference

B = randn(2,1); % Same with point B

d = norm(B-A);

R = d/2+rand; % Choose R radius >= d/2

C = (B+A)/2+sqrt(R^2-d^2/4)/d*[0,-1;1,0]*(B-A); % Center of circle

a = atan2(A(2)-C(2),A(1)-C(1));

b = atan2(B(2)-C(2),B(1)-C(1));

b = mod(b-a,2*pi)+a; % Ensure that arc moves counterclockwise

t = linspace(a,b,1000);

x = C(1)+R*cos(t);

y = C(2)+R*sin(t);

plot(x,y,'y-',C(1),C(2),'w*')

axis equal

Note that another possible center can be obtained by

C2 = (B+A)/2-sqrt(R^2-d^2/4)/d*[0,-1;1,0]*(B-A);

Note 2: If C is chosen, the arc will be <= pi. If C2 is used, arc will be >= pi

Ade Ade
on 9 Jul 2019

%Equation of a circle with centre (a,b) is (x-a)^2+ (y-b)^2 = r^2

%Circle Centre (1,1), radius = 10

k=1; %counter

c =1 ; % value of x at the centre of the circle

while c <=11

x(k) = c ;

vv = (c-1)^2 ;

y (k) = 1 + real (sqrt (100 - vv) );

c= c + 0.02;

k=k+1;

end

plot (x, y, 'r')

axis equal

Navinda Wickramasinghe
on 17 Sep 2020

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

Start Hunting!