Cody

# Problem 45912. Bounding Circle

Solution 2586334

Submitted on 19 Jun 2020 by Rafael S.T. Vieira
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('boundingCircle.m'); filetext(find(filetext == '%', 1, 'last') : end) = []; assert(isempty(strfind(filetext, '&gt;')), 'File handling is forbidden.'); assert(isempty(strfind(filetext, 'eval')), 'Eval forbidden.'); assert(isempty(strfind(filetext, 'regexp')), 'Regexp forbidden.'); assert(isempty(strfind(filetext, '!')), 'Shell commands are forbidden.'); assert(isempty(strfind(filetext, 'mlock')), 'mlock is forbidden.'); assert(isempty(strfind(filetext, 'munlock')), 'munlock is forbidden.'); assert(isempty(strfind(filetext, '@')), 'Anonymous functions are forbidden.');

2   Pass
Xp=[2 2 1]'; Yp=[1 3 2]'; [r,x,y]=boundingCircle(Xp,Yp); x_c=2; y_c=2; r_c=1; assert(abs(x-x_c)<1e-10 & abs(y-y_c)<1e-10 & abs(r-r_c)<1e-10);

3   Pass
Xp=[2 3 5 1 3]'; Yp=[2 3 5 2 2]'; [r,x,y]=boundingCircle(Xp,Yp); x_c=3; y_c=3.5; r_c=2.5; assert(abs(x-x_c)<1e-10 & abs(y-y_c)<1e-10 & abs(r-r_c)<1e-10);

4   Pass
Xp=[8 1 7 9 2 9 4 3 7]'; Yp=[5 6 2 5 9 9 7 6 7]'; [r,x,y]=boundingCircle(Xp,Yp); x_c=5.48; y_c=6.22; r_c=4.4854; assert(abs(x-x_c)<1e-3 & abs(y-y_c)<1e-3 & abs(r-r_c)<1e-3);

5   Pass
Xp=[6 2 7 3 3 4 7 7 4]'; Yp=[5 3 4 5 7 7 4 7 3]'; [r,x,y]=boundingCircle(Xp,Yp); x_c=4.5; y_c=5.0; r_c=3.20156; assert(abs(x-x_c)<1e-4 & abs(y-y_c)<1e-4 & abs(r-r_c)<1e-3);

6   Pass
n=100; Xp=randn(n,1); Yp=randn(n,1); [r,x,y]=boundingCircle(Xp,Yp); % All points lie inside the circle? D=sqrt((Xp-x).^2+(Yp-y).^2); % At least one most distant point falls on the circumference? d=sqrt((Xp-Xp').^2+(Yp-Yp').^2); [~,k]=max(d,[],'all','linear'); [k1,k2]=ind2sub(size(d),k); r1=sqrt((Xp(k1)-x)^2+(Yp(k1)-y)^2); r2=sqrt((Xp(k2)-x)^2+(Yp(k2)-y)^2); assert(max(D) <= r+eps & (abs(r1-r) < 1e-4 | abs(r2-r) < 1e-4));

### Community Treasure Hunt

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

Start Hunting!