Under construction

Still being built. Things may change

3D Geometry

Time limit1sMemory limit1024 MB

Summary
Given an axis-aligned tetrahedron and an axis-aligned cube in each test case, the task is to find the volume of their intersection.
Level

Medium7 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

An axis-aligned tetrahedron (triangular pyramid) DABCDABC is a convex polyhedron in three dimensions with these vertices:

  • D:(x1,y1,z1)D: (x_1, y_1, z_1)
  • A:(x2,y1,z1)A: (x_2, y_1, z_1)
  • B:(x1,y2,z1)B: (x_1, y_2, z_1)
  • C:(x1,y1,z2)C: (x_1, y_1, z_2)

An axis-aligned cube PQRSDEFGPQRSDEFG is also a convex polyhedron, with these vertices:

  • P:(x3,y3,z3)P: (x_3, y_3, z_3)
  • Q:(x3,y3,z4)Q: (x_3, y_3, z_4)
  • R:(x3,y4,z3)R: (x_3, y_4, z_3)
  • S:(x3,y4,z4)S: (x_3, y_4, z_4)
  • D:(x4,y3,z3)D: (x_4, y_3, z_3)
  • E:(x4,y3,z4)E: (x_4, y_3, z_4)
  • F:(x4,y4,z3)F: (x_4, y_4, z_3)
  • G:(x4,y4,z4)G: (x_4, y_4, z_4)

Given the tetrahedron DABCDABC and the cube PQRSDEFGPQRSDEFG, find the volume of their intersection.

Input

The input contains several test cases and ends at end-of-file. Each test case has 4 lines. The ii-th line contains three integers xix_i, yiy_i, and ziz_i.

Output

For each test case, print the volume as a real number. Your answer is accepted if its absolute or relative error does not exceed 10−610^{-6}.

Constraints

  • −500≤xi,yi,zi≤500-500 \le x_i, y_i, z_i \le 500 for each 1≤i≤41 \le i \le 4
  • x1≠x2x_1 \neq x_2, y1≠y2y_1 \neq y_2, z1≠z2z_1 \neq z_2
  • x3≠x4x_3 \neq x_4, y3≠y4y_3 \neq y_4, z3≠z4z_3 \neq z_4
  • The number of test cases does not exceed 10510^5.

Examples1

  1. Example 1

    Input
    0 0 0
    1 1 1
    0 0 0
    1 1 1
    0 0 0
    2 2 2
    0 0 0
    1 1 1
    0 2 0
    2 0 2
    1 0 1
    0 1 0
    
    Expected output
    0.166666667
    0.833333333
    0.166666667