is to give six algorithms about a circle. Implement them.
Note that the output format is not just the same symbol or something. The order of coordinates is also small to large ...
Basically did not consider what the accuracy of the problem, and then the past.
The rat is lying again. Maybe my method is better?
What I do is column equations + rotation + panning
My Code:
#include <iostream> #include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath> #include <queue> #include <vector> #include <algorithm >using namespace Std;const double Eps=1e-7;const double Pi=acos ( -1.0); int dcmp (double x) {return fabs (x) <eps?0:x <0?-1:1;} struct dot{double X,y;dot () {}dot (double a,double b) {x=a;y=b;} Dot operator + (dot a) {return dot (x+a.x,y+a.y);} Dot operator-(dot a) {return dot (x-a.x,y-a.y);} Dot operator * (double a) {return dot (x*a,y*a);} Double operator * (dot a) {return x*a.y-y*a.x;} Dot operator/(double a) {return dot (x/a,y/a);} Double operator/(dot a) {return x*a.x+y*a.y;} BOOL operator = = (dot a) {return x==a.x&&y==a.y;} void in () {scanf ("%lf%lf", &x,&y);} void out () {printf ("%f%f\n", x, y);} Dot Norv () {return dot (-y,x);} Dot Univ () {double a=mod (); return dot (x/a,y/a);} Dot ro (Double a) {return dot (X*cos (a)-y*sin (a), X*sin (a) +y*cos (a)); Double mod () {return sqrt (x*x+y*y);} Double dis (dot a) {return sqrt (POW (x-a.x,2) +pow (y-a.y,2));}}; BOOL operator > (dot A,dot b) {return dcmp (a.x-b.x)!=0?
A.X>B.X:A.Y>B.Y;} struct Fun {double a,b,c; Fun () {} fun (double x,double y,double z) {a=x;b=y;c=z;} Fun (dot D,dot e) {a=e.y-d.y;b=d.x-e.x;c=d.x*e.y-d.y*e.x;} Dot sf (fun D) {double E,f,g;e=dot (a,d.a) *dot (b,d.b); F=dot (C,D.C) *dot (b,d.b); G=dot (A,D.A) *dot (C,D.C); return dot (f/e, g/e);} void in () {scanf ("%lf%lf%lf", &a,&b,&c);} void out () {printf ("%f%f%f\n", a,b,c);}; void solve1 (dot A,dot b,dot c) {dot G;fun e,f;double r;e=fun ((a+b)/2, (A+B)/2+ (A-B). Norv ()); F=fun ((A+c)/2, (A+c)/2+ (a-c) . Norv ()); g=e.sf (f); R=g.dis (a);p rintf ("(%.6LF,%.6LF,%.6LF) \ n", g.x,g.y,r);} void Solve2 (dot A,dot b,dot c) {double e,d,f,g,r;fun h,i;dot J;d=a.dis (b); E=a.dis (c); F=b.dis (c); G=acos ((d*d+e*e-f*f)/2 /d/e)/2;if (dcmp ((b-a) * (c-a)) >0) H=fun (A, (b-a). RO (g) +a); Elseh=fun (A, (c-a). RO (g) +a); G=acos ((e*e+f*f-d*d)/2/e/f )/2;if (dcmp ((a-c) * (b-c)) >0) I=fun (c, (a-c). RO (g) +c); Elsei=fun (c, (b-c). RO (g) +c); j=h.sf (i); R=fabs ((j-a) * (B-A)/ A.dis (b));p rintf ("(%.6LF,%.6LF,%.6LF) \ n", j.x,j.y,r); Double CG (dot a) {DOuble b=atan2 (a.y,a.x); B=b/pi*180;return dcmp (b) <0?
B+180:DCMP (b-180)!=0?b:0;} void Solve3 (dot a,double r,dot p) {dot d,g;double B,c,e,f;b=a.dis (p); C=asin (r/b); if (dcmp (b-r) <0) printf ("[]\n"); else if (dcmp (b-r) ==0) {d= (p-a). Norv (); E=CG (d);p rintf ("[%.6f]\n", e);} Else{d= (a-p). RO (c); g= (a-p). RO (2*pi-c); E=CG (d); F=CG (g); if (e>f) swap (e,f);p rintf ("[%.6f,%.6f]\n", e,f);} void Solve4 (dot p,dot a,dot b,double r) {Double D,e;dot c,f,g;c=fun (A, b). SF (Fun (p,p+ (a). Norv ()));d =p.dis (c); if (DCMP ( D-2*R) >0) printf ("[]\n"); else if (dcmp (d) ==0) {f=p+ (A-B). Norv (). Univ () *r;g=p-(A-B) Norv (). Univ () *r;if (F>G) Swap (F,G);p rintf ("[(%.6f,%.6f), (%.6f,%.6f)]\n", f.x,f.y,g.x,g.y);} else if (dcmp (d-2*r) ==0) {f= (p+c)/2;printf ("[(%.6f,%.6f)]\n", F.X,F.Y);} Else{e=acos ((d-r)/R); f= ((C-p). Univ () *r). RO (E) +p;e=-e;g= ((c-p). Univ () *r). RO (e) +p;if (f>g) Swap (f,g);p rintf ("[( %.6f,%.6f), (%.6f,%.6f)]\n ", F.x,f.y,g.x,g.y);}} void Solve5 (dot a,dot b,dot C,dot d,double r) {dot i,j,k,l;double t1,t2;fun e,f,g,h;e=fun (A, b); F=fun (c,d); T1=sqrt (POW ( e.a,2) +pow (e.b,2)) t2=sqrt (Pow (f.a,2) +pow (f.b,2)); G=fun(e.a/t1,e.b/t1,e.c/t1+r); H=fun (f.a/t2,f.b/t2,f.c/t2+r); I=G.SF (h); G.C=E.C/T1-R;J=G.SF (h); H.C=F.C/T2-R;K=G.SF (h) , G.C=E.C/T1+R;L=G.SF (h), if (i>j) swap (I,J), if (i>k) swap (i,k), if (i>l) swap (i,l), if (j>k) swap (j,k), if (j >l) Swap (j,l), if (k>l) swap (k,l);p rintf ("[(%.6f,%.6f), (%.6f,%.6f), (%.6f,%.6f), (%.6f,%.6f)]\n", i.x,i.y,j.x, J.Y,K.X,K.Y,L.X,L.Y);} void Solve6 (dot a,double r1,dot b,double r2,double r) {dot f,g;double C,d,e,h;c=a.dis (b);d =r1+r;e=r2+r;if (dcmp ( C-R-R-R1-R2) >0) printf ("[]\n"); else if (dcmp (C-R-R-R1-R2) ==0) {f=a+ (b-a). Univ () * (r1+r);p rintf ("[(%.6f,%.6f)]\n" , F.X,F.Y);} Else{h=acos ((c*c+d*d-e*e)/2/c/d) f= ((b-a). Univ () * (R1+R)). RO (h) +a;h=-h;g= ((b-a). Univ () * (R1+R)). RO (h) +a;if (f> g) Swap (f,g);p rintf ("[(%.6f,%.6f), (%.6f,%.6f)]\n", F.x,f.y,g.x,g.y);}} int main () {char s[100];d ot a,b,c,d;double r,r1,r2;while (scanf ("%s", s)!=eof) {if (strcmp (S, "circumscribedcircle") ==0) {a.in (); b.in (); c.in (); solve1 (a,b,c);} else if (strcmp (S, "inscribedcircle") ==0) {a.in (); b.in (); c.in (); Solve2 (a,b,c);} else if (strcmp(S, "Tangentlinethroughpoint") ==0) {a.in (); cin>>r;b.in (); Solve3 (a,r,b);} else if (strcmp (S, "Circlethroughapointandtangenttoalinewithradius") ==0) {a.in (); b.in (); c.in (); cin>>r;solve4 (a,b,c,r);} else if (strcmp (S, "Circletangenttotwolineswithradius") ==0) {a.in (); b.in (); c.in ();d. in (); Cin>>r;solve5 (a,b,c , d,r);} Else{a.in (); cin>>r1;b.in (); Cin>>r2;cin>>r;solve6 (a,r1,b,r2,r);}} /*solve1 (dot (0,0), Dot (20,1), Dot (8,17)), Solve2 (dot (0,0), Dot (20,1), Dot (8,17)), Solve3 (dot (200,200), 100,dot (40,150 ); Solve3 (dot (200,200), 100,dot (200,100)), Solve3 (dot (200,200), 100,dot (270,210)), Solve4 (dot (100,200), Dot (75,190) , Dot (185,65), Solve4 (dot (75,190), Dot (75,190), Dot (185,65), and Solve4 (dot (100,300), Dot (100,100), Dot (200,100 ), Solve4 (dot (100,300), Dot (100,100), Dot (200,100), and Solve5 (dot (50,80), Dot (320,190), Dot (85,190), Dot (125,40 ), Solve6 (dot (120,200), 50,dot (210,150), 30,25), Solve6 (dot (100,100), 80,dot (300,250), 70,50); */}
Description
Problem e2d Geometry in 1!
This is a collection of the (in binary) 2D geometry problems.
circumscribedcircle x1 y1 x2 y2 x3 y3
Find out the circumscribed circle of Triangle (x1,y1)-(X2,y2)-(X3,Y3). These three points is guaranteed to be non-collinear. The circle is formatted as (X,Y,R) where (x, y) is the center of Circle, which is the radius.
inscribedcircle x1 y1 x2 y2 x3 y3
Find out the inscribed circle of Triangle (x1,y1)-(X2,y2)-(X3,Y3). These three points is guaranteed to be non-collinear. The circle is formatted as (X,Y,R) where (x, y) is the center of Circle, which is the radius.
Tangentlinethroughpoint XC YC r XP YP
Find out the list of tangent lines of circle centered (XC,YC) with radius r, that pass, through Point (XP,YP). Each tangent line was formatted as a single real number "angle" (degrees) and the angle of the line (0<=angle<180). Note that the answer should is formatted as a list (see below for details).
Circlethroughapointandtangenttoalinewithradius xp yp x1 y1 x2 y2 r
Find out the list of circles passing through point (XP, YP) as tangent to a line (x1,y1)-(x2,y2) with radius R. Each circle is formatted as (x, y), since the radius is already given. Note that the answer should is formatted as a list. If There is no answer, you should print an empty list.
circletangenttotwolineswithradius x1 y1 x2 y2 x3 y3 x4 y4 R
Find out the list of circles tangent to double non-parallel lines (x1,y1)-(X2,y2) and (X3,y3)-(X4,Y4), having radius r. Each circle is formatted as (x, y), since the radius is already given. Note that the answer should is formatted as a list. If There is no answer, you should print an empty list.
circletangenttotwodisjointcircleswithradius x1 y1 R1 x2 y2 R2 r
Find out the list of circles externally tangent to the disjoint circles (X1,Y1,R1) and (X2,Y2,R2), having radius r. By "externally" we mean it should not enclose the other given circles. Each circle is formatted as (x, y), since the radius is already given. Note that the answer should is formatted as a list. If There is no answer, you should print an empty list.
For each line described above, the both endpoints is not being equal. When formatting a list of real numbers, the numbers should is sorted in increasing order; When formatting a list of (x, y) pairs, the pairs should is sorted in increasing order of X. In case of tie, smaller y comes first.
Input
There'll is at the most sub-problems, one on each line, formatted as above. The coordinates is integers with absolute value not greater than 1000. The input is terminated by end of file (EOF).
Output
For each input line, print out your answer formatted as stated in the problem description. Each number in the output should is rounded to six digits after the decimal point. Note that the list should is enclosed by square brackets, and tuples should is enclosed by brackets. There should is no space characters in each line of your output.
Sample Input
Circumscribedcircle 0 0 1 8 17InscribedCircle 0 0 1 8 150TangentLineThrough 17TangentLineThroughPoint Point @ 100TangentLineThroughPoint 210CircleThroughAPointAndTangentToALineWithRadius 100 200 185 100CircleThroughAPointAndTangentToALineWithRadius, 185 100CircleThroughAPointAndTangentToAL Inewithradius, 100CircleThroughAPointAndTangentToALineWithRadius, 99CircleTa,. Ngenttotwolineswithradius 30CircleTangentToTwoDisjointCirclesWithRadius 120 200 50 210 150 30 25CircleTangentToTwoDisjointCirclesWithRadius 100 100 80 300 250 70 50
Output for the Sample Input
(9.734940,5.801205,11.332389) (9.113006,6.107686,5.644984) [53.977231,160.730818] [0.000000] [(112.047575,299.271627), (199.997744,199.328253)] [( -0.071352,123.937211), (150.071352,256.062789)] [( 100.000000,200.000000)][][(72.231286,121.451368), (87.815122,63.011983), (128.242785,144.270867), ( 143.826621,85.831483) [(157.131525,134.836744), (194.943947,202.899105)] [(204.000000,178.000000)]
Rujia Liu ' s Present 4:a Contest dedicated to Geometry and CG Lovers
Special Thanks:di Tang and Yi Chen
Source
Root:: Prominent problemsetters:: Rujia Liu
Root:: Rujia Liu ' s Presents:: Present 4:dedicated to Geometry and CG Lovers
Root:: AOAPC i:beginning Algorithm Contests--Training Guide (Rujia Liu):: Chapter 4. Geometry:: Geometric computations in 2D:: Examples
Uva12304-2d Geometry in 1!