QOJ.ac

QOJ

実行時間制限: 30.0 s メモリ制限: 256 MB 満点: 100

#17525. 两个棱柱的交

統計

假设 $P_1$ 是一个轴平行于 $z$ 轴的无限高棱柱,而 $P_2$ 也是一个轴平行于 $y$ 轴的无限高棱柱。$P_1$ 由多边形 $C_1$ 定义,该多边形是 $P_1$ 与 $xy$ 平面的截面;$P_2$ 由多边形 $C_2$ 定义,该多边形是 $P_2$ 与 $xz$ 平面的截面。

图 I.1 展示了样例输入中第一个数据集对应的两个截面,图 I.2 展示了这两个棱柱及其截面之间的关系。

图 I.1:棱柱的截面

图 I.2:棱柱及其截面

图 I.3 展示了图 I.2 中两个棱柱 $P_1$ 和 $P_2$ 的交集。

图 I.3:两个棱柱的交集

请编写一个程序,计算这两个棱柱交集的体积。

输入格式

输入包含多组数据集。数据集的数量少于 200 组。

每个数据集的格式如下:

m n
x11 y11
x12 y12
...
x1m y1m
x21 z21
x22 z22
...
x2n z2n

$m$ 和 $n$ 是整数($3 \le m \le 100$,$3 \le n \le 100$),分别表示多边形 $C_1$ 和 $C_2$ 的顶点数。

$x_{1i}$、$y_{1i}$、$x_{2j}$ 和 $z_{2j}$ 是介于 $-100$ 和 $100$ 之间的整数(包含边界)。$(x_{1i}, y_{1i})$ 和 $(x_{2j}, z_{2j})$ 分别表示 $C_1$ 和 $C_2$ 的第 $i$ 个和第 $j$ 个顶点的坐标。

这些顶点坐标的序列在 $xy$ 平面或 $xz$ 平面上按逆时针顺序给出,如图 I.1 所示。

你可以假设所有的多边形都是凸多边形,即多边形的所有内角都小于 180 度。你也可以假设所有的多边形都是简单多边形,即每个多边形的边界不会自交或自切。

输入结束由包含两个零的一行(0 0)表示。

输出格式

对于每个数据集,在一行中输出两个棱柱 $P_1$ 和 $P_2$ 交集的体积,用小数表示。

输出值的误差不得大于 $0.001$。输出中不应包含任何其他多余字符。

样例

输入样例 1

4 3
7 2
3 3
0 2
3 1
4 2
0 1
8 1
4 4
30 2
30 12
2 12
2 2
15 2
30 8
13 14
2 8
8 5
13 5
21 7
21 9
18 15
11 15
6 10
6 8
8 5
10 12
5 9
15 6
20 10
18 12
3 3
5 5
10 3
10 10
20 8
10 15
10 8
4 4
-98 99
-99 -99
99 -98
99 97
-99 99
-98 -98
99 -99
96 99
0 0

输出样例 1

4.708333333333333
1680.0000000000005
491.1500000000007
0.0
7600258.4847715655

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.