practice test

%Exam 2


[x1,x2,x3] = Input_the_data();
[center,radius] = Do_calculations(x1,x2,x3);
Plot_the_result(center,radius,x1,x2,x3)


function Plot_the_result(cen, rad, p1,p2,p3)
Ct=[cen(1),cen(2)];
Ct=round(Ct*100)/100;
t=linspace(0,pi,100);
xp=Ct(1)+rad*cos(t);
ypt=Ct(2)+rad*sin(t);
ypb=Ct(2)-rad*sin(t);
figure(20)
plot(xp,ypt,'b',xp,ypb,'b',p1(1),p1(2),'*',p2(1),p2(2),'*',p3(1),p3(2),'*',Ct(1),Ct(2),'*')
title('Function plot')
xlabel('X-Axis')
ylabel('Y-Axis')
axis equal

end


function [C,R] = Do_calculations( a,b,c )

A = 2 * [a(1) - b(1) a(2)-b(2); b(1)-c(1) b(2)-c(2)];
B = [a(1)^2+a(2)^2-b(1)^2-b(2)^2; b(1)^2+b(2)^2-c(1)^2-c(2)^2];
C = A\B;
R = sqrt((a(1)-C(1))^2 + (a(2)-C(2))^2);
fprintf('\nThe coordinates of the center are (%.1f, %.1f) ', C)
fprintf(' and the radius is %.1f.\n',R)

end
function [A B C] = Input_the_data()

A = input('Please enter the coordinates of point 1 as a vector [x x]: ');
B = input('Please enter the coordinates of point 2 as a vector [x x]: ');
C = input('Please enter the coordinates of point 3 as a vector [x x]: ');


end