MATLAB exercise program (Ritter's smallest circle)

Source: Internet
Author: User

The original algorithm is sphere, which is simplified to circle here.

Ritter's Algorithm for Finding the smallest enclosed circle is a linear algorithm, which is widely used because it is very simple.

The circle obtained by this algorithm is about 5% to 20% larger than the optimal circle. You can use the bouncing bubble algorithm to find the optimal circle. You can try it later.

Ritter's algorithm is as follows:

1. Randomly select two points from the vertex set as the diameter to initialize the circle.

2. Determine whether the next vertex P is in the circle. If it is in the circle, continue this step. If not, proceed to step 3.

3. Use P as one boundary point of the new circle, and the other boundary point is the point on the circle farthest from P. Use these two points as the diameter to construct the new circle.

4. Continue Step 2 until all vertices are traversed.

The result is as follows:

The Matlab code is as follows:

clear all;close all;clc;n=100;p=rand(n,2);p1=p(1,:);p2=p(2,:);r=sqrt((p1(1)-p2(1))^2+(p1(2)-p2(2))^2)/2;cenp=(p1+p2)/2;for i=3:n    newp=p(i,:);        d=sqrt((cenp(1)-newp(1))^2+(cenp(2)-newp(2))^2);      if d>r        r=(r+d)/2;        cenp=cenp+(d-r)/d*(newp-cenp);    end    endhold on;plot(p(:,1),p(:,2),‘o‘);x0=cenp(1);y0=cenp(2);theta=0:0.01:2*pi;x=x0+r*cos(theta);y=y0+r*sin(theta);plot(x,y,‘-‘,x0,y0,‘.‘);axis equal

Reference: http://en.wikipedia.org/wiki/Bounding_sphere

MATLAB exercise program (Ritter's smallest circle)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.