hdu6206
Test instructions: Give 4 points and ask whether the 4th point is circumscribed circle outside the first three points.
Tags: there will be precision problems, on Java.
1 "formula
Three point coordinates are known, circumscribed Circle Center coordinates and RADIUS are obtained.
// Three point coordinates are known, circumscribed Circle Center coordinates and RADIUS are obtained. x= ((y2-y1) * (y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1) * (Y2*Y2-Y1*Y1+X2*X2-X1*X1))/(2.0* ((X3-X1) * (y2-y1)-( X2-X1) * (y3-y1)); y= ((x2-x1) * (x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1) * (x2*x2-x1*x1+y2*y2-y1*y1))/(2.0 * ((y3-y1) * (x2-x1)-(y2-y1) * (x3-x1)), R^2= (x1-a) * (x1-a) + (y1-b) * (y1-b);
//Package Project1;import java.util.*; import Java.math.*; import Java.util.Scanner; Public classMain {//Test2 { Public Static voidMain (string[] argv) throws Exception {Scanner sc=NewScanner (System.inch); Mathcontext MC=NewMathcontext (7, Roundingmode.half_down); intT =Sc.nextint (); for(intcas=1; cas<=t; ++CAs) {BigDecimal x1=sc.nextbigdecimal (), Y1=sc.nextbigdecimal (), X2=sc.nextbigdecimal (), y2=Sc.nextbigdecimal (); BigDecimal X3=sc.nextbigdecimal (), Y3=sc.nextbigdecimal (), X4=sc.nextbigdecimal (), y4=Sc.nextbigdecimal (); BigDecimal x, Y, R; BigDecimal A1=y2.subtract (y1), a2=y3.multiply (Y3), a3=y1.multiply (y1), a4=x3.multiply (x3), a5=x1.multiply (x1); BigDecimal A6= (Y2.subtract (y1)). Multiply (Y3.pow (2). Subtract (Y1.pow (2). Add (X3.pow (2). Subtract (X1.pow (2))); BigDecimal A7= (Y3.subtract (y1)). Multiply (Y2.pow (2). Subtract (Y1.pow (2). Add (X2.pow (2). Subtract (X1.pow (2)))); A1=bigdecimal.valueof (2); A2=x3.subtract (x1); A3=y2.subtract (y1); A4=x2.subtract (x1); A5=y3.subtract (y1); BigDecimal A8=a1.multiply ((A2). Multiply (A3). Subtract (A4.multiply (A5))); X=A6.subtract (A7). Divide (A8); A6= (X2.subtract (x1)). Multiply (X3.pow (2). Subtract (X1.pow (2). Add (Y3.pow (2). Subtract (Y1.pow (2))); A7= (X3.subtract (x1)). Multiply (X2.pow (2). Subtract (X1.pow (2). Add (Y2.pow (2). Subtract (Y1.pow (2)))); A1=bigdecimal.valueof (2); A2=y3.subtract (y1); A3=x2.subtract (x1); A4=y2.subtract (y1); A5=x3.subtract (x1); A8=a1.multiply (a2.multiply (A3) Subtract (A4.multiply (A5))); Y=A6.subtract (A7). Divide (A8); A1= (X1.subtract (x). POW (2)); A2= (Y1.subtract (y). Pow (2)); R=A1.add (A2); A1= (X.subtract (x4). POW (2)); A2= (Y.subtract (y4). POW (2)); BigDecimal Dis=A1.add (A2); //System.out.println (x+ "" +y+ "" +r+ "" +dis+ "-----"); if(Dis.compareto (R) >0) System. out. println ("Accepted"); ElseSystem. out. println ("rejected"); } }}/*Three point coordinates are known, circumscribed Circle Center coordinates and RADIUS are obtained. X= ((y2-y1) * (y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1) * (Y2*Y2-Y1*Y1+X2*X2-X1*X1))/(2.0* ((x3-x1) * (y2-y1)-(x2-x1) * (y3-y1)) ); y= ((x2-x1) * (x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1) * (x2*x2-x1*x1+y2*y2-y1*y1))/(2.0* ((y3-y1) * (x2-x1)-(y2-y1) * (x3-x1 )); r^2= (x1-a) * (x1-a) + (y1-b) * (y1-b);*/View Code
2 "function
//find a circle at three.Circle findCircle2 (P p1, p P2, p p3) {DoubleA1, A2, B1, B2, C1, C2, temp; A1= p1.x-p2.x; B1= P1.y-p2.y; C1= (p1.x*p1.x-p2.x*p2.x + p1.y*p1.y-p2.y*p2.y)/2; A2= p3.x-p2.x; B2= P3.y-p2.y; C2= (p3.x*p3.x-p2.x*p2.x + p3.y*p3.y-p2.y*p2.y)/2; Temp= a1*b2-a2*B1; Circle CD; Cd.center.x= (C1*B2-C2*B1)/temp; Cd.center.y= (A1*C2-A2*C1)/temp; Cd.radius= Sqrtf ((cd.center.x-p1.x) * (cd.center.x-p1.x) + (CD.CENTER.Y-P1.Y) * (CD.CENTER.Y-p1.y)); returnCD;}
hdu6206 Apple Java, find circumscribed circle at three.