Point Coverage circle

Source: Internet
Author: User

1. Question proposal
The coordinates of the eight points on the known plane are ), try to find the minimum radius of the circle that covers 8 points.

2. Design Ideas
① If there are only two points on the circumference of the smallest circle, the line between the two points is regarded as the smuggling of the circle.
② If there are three (or more) points on the circumference of the smallest congratulation, the smallest circle is the outer circle of the three (or more) points.
To obtain an external circle, follow these steps:
(1) obtain the distance L1 from two points (x1, Y1) and (X2, Y2:
L1 = SQRT (x1-x2) ^ 2 + (y1-y2) ^ 2)
(2) If the three sides are known to be L1, L2, and L3, calculate the Triangle Area:
L = (l1 + l2 + l3)/2 (half perimeter)
(3) Calculate the outer circle radius R based on the formula 4sr = L1 * L2 * L3:
R = L1 * L2 * L3/(4 * s)
Therefore, to obtain the smallest circle Covering N points, you only need to find the smallest circle covered by all the three points, and the radius of the circle is obtained.
Determine the smallest circle that covers three points: if the sum of squares of one side is greater than or equal to the sum of squares of the other two sides, that is, three points form a right-angle or right-angle triangle, or three points are collocated, the diameter of the smallest circle is the longest side.
Otherwise, three points form an acute triangle, and the smallest circle is the outer circle of three points.
By setting the combination of all the three vertices for N points, compare all the minimum circular radius to their maximum values.

3. Code Implementation

// Program Design of Point Coverage circle <br/> // obtain the smallest circle Covering N Points <br/> # include <math. h> <br/> # include <stdio. h> </P> <p> int main (void) <br/> {<br/> int I, n, a, B, c, A0, B0, C0, am, BM, CM, T, W; <br/> double L, L1, L2, L3, R, S, max = 0; <br/> double X [50], Y [50]; </P> <p> printf ("Number of Input Points N :"); // determine the number of points of a known point <br/> scanf ("% d", & N); <br/> for (I = 1; I <= N; I ++) {<br/> printf ("Enter the coordinates of point % d:", I); <br/> scanf ("% lf ", & X [I], & Y [I]); <br/>} </P> <p> // A, B, and C triplicate loops use all three combinations <br/> for (a = 1; A <= N-2; A ++) {<br/> for (B = a + 1; B <= n-1; B ++) <br/> for (C = B + 1; c <= N; C ++) {<br/> L1 = SQRT (X [B]-X [c]) * (X [B]-X [c]) + (Y [B]-y [c]) * (Y [B]-y [c]); <br/> L2 = SQRT (X [a]-X [c]) * (X [a]-X [c]) + (Y [a]-y [c]) * (Y [a]-y [c]); <br/> l3 = SQRT (X [B]-X [a]) * (X [B]-X [a]) + (Y [B]-y [a]) * (Y [B]-y [a]); <br/> L = (l1 + L2 + l3)/2; <br/> S = SQRT (L * (L-L1) * (L-L2) * (L-l3 )); // Triangle Area </P> <p> // when the right angle is blunt or collocated, R is half of the longest side <br/> If (L2 * l2 + l3 * L3 <= L1 * L1) {<br/> r = L1/2; <br/> b0 = B; <br/> C0 = C; <br/> T = 1; <br/>}< br/> else if (L3 * L3 + L1 * L1 <= L2 * l2) {<br/> r = L2/2; <br/> a0 = A; <br/> C0 = C; <br/> T = 2; <br/>}< br/> else if (L1 * l1 + l2 * L2 <= L3 * l3) {<br/> r = L3/2; <br/> A0 = A; <br/> b0 = B; <br/> T = 3; <br/>}< br/> else {<br/> r = L1 * L2 * L3/(4 * s ); // calculate the outer circle radius r <br/> a0 = A; <br/> b0 = B; <br/> C0 = C; <br/> T = 0; <br/>}< br/> If (r> MAX) {<br/> max = r; <br/> W = T; <br/> AM = A0; <br/> Bm = b0; <br/> CM = C0; <br/>}</P> <p> printf ("the minimum radius of the circle covered by more than % d points is %. 4f/N ", N, max); <br/> printf (" the points on the circumference of the circle are: "); <br/> If (! W) // W = 0 the smallest circle is a three-point external circle <br/> printf ("(% G, % G), (% G, % G), (% G, % G) ", X [Am], Y [Am], X [BM], Y [BM], X [cm], Y [cm]); <br/> else if (1 = W) <br/> printf ("(% G, % G), (% G, % G )", X [BM], Y [BM], X [cm], Y [cm]); <br/> else if (2 = W) <br/> printf ("(% G, % G), (% G, % G)", X [Am], Y [Am], X [cm], Y [cm]); <br/> else if (3 = W) <br/> printf ("(% G, % G), (% G, % G) ", X [Am], Y [Am], X [BM], Y [BM]); <br/> putchar ('/N '); </P> <p> return 0; <br/>}

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.