1 // PROBLEMA DE GEOMETIRA, 2 cortes en una torta, y calcula el volumen de cada pedazo :D
21 #define REP(i, n) for(int i=0;i<int(n);i++)
22 #define foreach(it, c) for(typeof((c).begin()) it = (c).begin();it!=(c).end();++it)
23 #define ALL(x) (x).begin(),(x).end()
24 #define SORT(x) sort(ALL(x))
26 #define VI vector<int>
27 #define VS vector<string>
37 if( a
>= 0.0 ) return 1;
40 double prodcruz(point p1
, point p2
, point p3
){
41 double x1
, x2
, y1
, y2
;
42 x1
= p2
.x
-p1
.x
; x2
= p3
.x
-p1
.x
;
43 y1
= p2
.y
-p1
.y
; y2
= p3
.y
-p1
.y
;
44 return fabs(x1
*y2
-x2
*y1
)/2.0;
46 double prodcruz2(point p1
, point p2
, point p3
){
47 double x1
, x2
, y1
, y2
;
48 x1
= p2
.x
-p1
.x
; x2
= p3
.x
-p1
.x
;
49 y1
= p2
.y
-p1
.y
; y2
= p3
.y
-p1
.y
;
50 return (x1
*y2
-x2
*y1
)/2.0;
52 int equal(double a
, double b
){if( fabs(a
-b
) < EPS
) return 1; return 0;}
53 void points_to_line(point p1
, point p2
, line
& l
){
54 if(equal(p1
.x
, p2
.x
)){
60 l
.a
= -(p1
.y
-p2
.y
)/(p1
.x
-p2
.x
);
61 l
.c
= -(l
.a
*p1
.x
)-(l
.b
*p1
.y
);
65 double dist(point p1
, point p2
){
69 return sqrt(ax
*ax
+ay
*ay
);
71 double area(point p1
, point p2
, point p3
){
78 double aux
= a
*a
-b
*b
-c
*c
;
80 double angle
= acos(aux
);
81 double prop
= angle
/(acos(-1)*2.0);
82 if( signo(prodcruz2(p1
,p2
,p3
)) == signo(prodcruz2(p1
,p2
,p
))){
83 prop
*= (acos(-1)*R
*R
);
84 prop
-= prodcruz(p1
,p2
,p
);
85 prop
+= prodcruz(p1
,p2
,p3
);
88 prop
*= (acos(-1)*R
*R
);
89 prop
+= prodcruz(p1
,p2
,p
);
90 prop
+= prodcruz(p1
,p2
,p3
);
94 void intersection_point(line l1
, line l2
, point
&p
){
95 p
.x
= (l2
.b
*l1
.c
-l1
.b
*l2
.c
) / (l2
.a
*l1
.b
-l1
.a
*l2
.b
);
96 if( fabs(l1
.b
) > EPS
)
97 p
.y
= -(l1
.a
*p
.x
+l1
.c
)/l1
.b
;
99 p
.y
= -(l2
.a
*p
.x
+l2
.c
)/l2
.b
;
101 double cuad(double a
) { return a
*a
;}
102 double complementox(double x
, line l
){
103 double y
= sqrt(cuad(R
)-cuad(x
));
104 if( !equal(l
.a
*x
+l
.b
*y
+l
.c
, 0.0) ) return -y
;
107 double complementoy(double y
, line l
){
108 double x
= sqrt(cuad(R
)-cuad(y
));
109 if( !equal(l
.a
*x
+l
.b
*y
+l
.c
, 0.0) ) return -x
;
112 void line_to_points(line l
, point
&p1
, point
&p2
){
115 a
= cuad(l
.b
)/cuad(l
.a
)+1.0;
116 b
= (2.0*l
.c
*l
.b
)/cuad(l
.a
);
117 c
= cuad(l
.c
)/cuad(l
.a
)-cuad(R
);
118 p1
.y
= (-b
+sqrt(b
*b
-4.0*a
*c
))/(2.0*a
);
119 p2
.y
= (-b
-sqrt(b
*b
-4.0*a
*c
))/(2.0*a
);
120 p1
.x
= complementoy(p1
.y
, l
);
121 p2
.x
= complementoy(p2
.y
, l
);
124 a
= cuad(l
.a
)/cuad(l
.b
)+1.0;
125 b
= (2.0*l
.c
*l
.a
)/cuad(l
.b
);
126 c
= cuad(l
.c
)/cuad(l
.b
)-cuad(R
);
127 p1
.x
= (-b
+sqrt(b
*b
-4.0*a
*c
))/(2.0*a
);
128 p2
.x
= (-b
-sqrt(b
*b
-4.0*a
*c
))/(2.0*a
);
129 p1
.y
= complementox(p1
.x
, l
);
130 p2
.y
= complementox(p2
.x
, l
);
136 while(scanf("%i %i", &radio
, &h
) != EOF
){
139 REP(i
, 4)scanf("%lf %lf", &x
[i
], &y
[i
]);
141 REP(i
, 4)p
[i
].x
= x
[i
], p
[i
].y
= y
[i
];
143 points_to_line(p
[0], p
[1], l1
);
144 points_to_line(p
[2], p
[3], l2
);
145 line_to_points(l1
, p
[0], p
[1]);
146 line_to_points(l2
, p
[2], p
[3]);
148 intersection_point(l1
, l2
, P
);
150 areas
[0] = area(p
[0], p
[2], P
);
151 areas
[1] = area(p
[0], p
[3], P
);
152 areas
[2] = area(p
[1], p
[2], P
);
153 areas
[3] = area(p
[1], p
[3], P
);
154 sort(areas
, areas
+4);
155 printf("%.2lf %.2lf\n", (areas
[3])*(double)h
, (areas
[0])*(double)h
);