I'm storing hyper-regions as vectors in an SQL table like so:
region1: D1, D1', D2, D2', D3, D3'...DN, DN' region2: D1, D1', D2, D2', D3, D3'...DN, DN'
It's relatively easy to find regions that are non-intersecting, or entirely overlap. (
select from regions where D1 > foo, D2 < bar, etc). How can I determine the volume of intersection, in SQL, between two regions?
In three dimensions the calculation would look something like the following:
r1: X:0, X':2, Y:0, Y':2, Z:0, Z':2 r2: X:1, X':3, Y:1, Y':3, Z:0, Z':2 SELECT (mathmagic)
result: 2 (I have defined 2 cubes,
2x2x2, but the second cube is shifted 1 unit on both x and y axes, so the overlap is a 2x1 area)
Edit: A general formula would be fine too, doesn't have to be in SQL.