UVa 10351 - Cutting Diamonds

contents

  1. 1. Problem
  2. 2. Input
  3. 3. Output
  4. 4. Solution

Problem

給一個橢球的三個參數,一刀縱切橢球,問切割橢球的截面積為何。

Input

1
2
7 6 4 8 6 4
4 8 8 8 8 8

Output

1
2
3
4
Set #1
8.246681
Set #2
50.265482

Solution

回顧積分公式,得到橢圓面積。將橢球固定一個參數,調整計算截面積。公式如代碼中所附。

$$\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1 \\ \text{area } = ab\pi \\ \frac{x^2}{a^2} + \frac{y^2}{b^2} + \frac{z^2}{c^2} = 1 \\ \frac{x^2}{(a \sqrt{1 - z^2 / c^2})^2} + \frac{y^2}{(b \sqrt{1 - z^2 / c^2})^2} = 1 \\ \text{cross-sectional area} = ab (1 - z^2 / c^2) \pi \\$$
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <math.h>
using namespace std;
/*
x^2 / a^2 + y^2 / b^2 = 1
area = ab pi
x^2 / a^2 + y^2 / b^2 + z^2 / c^2 = 1
x^2 / (a \sqrt{1 - z^2 / c^2})^2 + y^2 / (b \sqrt{1 - z^2 / c^2})^2 = 1;
cross-sectional area = ab (1 - z^2 / c^2) pi
volume ab (1 - z^2 / c^2) pi dz
ab pi (z - z^3 / 3 / c^2), for z in [l, r]
*/
const double pi = acos(-1);
int main() {
int a, b, c, ra, rb, rc;
int cases = 0;
while (scanf("%d %d %d %d %d %d", &ra, &rb, &rc, &a, &b, &c) == 6) {
printf("Set #%d\n", ++cases);
double ta, tb, tc, l, r;
if (ra > a || rb > b || rc > c) {
printf("%.6lf\n", 0.0); // WTF
continue;
}
if (ra < a) {
ta = b/2.0, tb = c/2.0, tc = a/2.0;
r = a/2.0, l = r - fabs(a - ra);
} else if (rb < b) {
ta = a/2.0, tb = c/2.0, tc = b/2.0;
r = b/2.0, l = r - fabs(b - rb);
} else if (rc < c) {
ta = a/2.0, tb = b/2.0, tc = c/2.0;
r = c/2.0, l = r - fabs(c - rc);
} else {
printf("%.6lf\n", 0.0); // WTF
continue;
}
double area;
area = ta * tb * pi * (1 - l*l/tc/tc);
printf("%.6lf\n", area);
}
return 0;
}
/*
7 6 4 8 6 4
4 8 8 8 8 8
2 6 4 8 6 4
8 6 4 8 6 4
*/