# Calculating the 3d volume between arbitrary planes

**URL:** <https://discourse.julialang.org/t/calculating-the-3d-volume-between-arbitrary-planes/101793>\
**Category:** General Usage\
**Tags:** question, 3d, geometry, meshes\
**Created:** [July 19, 2023, 4:57pm UTC](https://discourse.julialang.org/t/calculating-the-3d-volume-between-arbitrary-planes/101793 "2023-07-19T16:57:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gavin\_Held](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gavin_held/32/49350_2.png) [@Gavin\_Held](https://discourse.julialang.org/u/Gavin_Held)\
**Post date:** [July 19, 2023, 4:57pm UTC](https://discourse.julialang.org/t/calculating-the-3d-volume-between-arbitrary-planes/101793/1 "2023-07-19T16:57:28Z")

</div>

![Screenshot from 2023-07-19 11-50-57](https://global.discourse-cdn.com/julialang/original/3X/6/e/6ee4270524827b2eb274fc6d1683145ff8bc5b3c.png)

Hello,

So I am trying to find an efficient way to calculate the volume between planes (e.g. the ones in the image). The planes are not parallel with one another, and I have not found any resources online that have been helpful. I was wondering if there is a julia package that is capable of doing something like this, or if not, some advice on calculating 3d object would be great.  
Thanks!

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [July 19, 2023, 5:00pm UTC](https://discourse.julialang.org/t/calculating-the-3d-volume-between-arbitrary-planes/101793/2 "2023-07-19T17:00:27Z")

</div>

Do you mean the volume of the convex hull of the shapes, or, if the planes were representing motion in space, the lines that connect the nearby vertices to form a hexahedron? Depending on how you wanted the shapes to be “skinned” you could get a few different answers.

---

<div class="post-metadata">

**Author:** ![Gavin\_Held](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gavin_held/32/49350_2.png) [@Gavin\_Held](https://discourse.julialang.org/u/Gavin_Held)\
**Post date:** [July 19, 2023, 5:02pm UTC](https://discourse.julialang.org/t/calculating-the-3d-volume-between-arbitrary-planes/101793/3 "2023-07-19T17:02:30Z")

</div>

I mean that if each of vertices were connected with a line to a neighboring plane to form a hexahedron, and then calculating the volume in between each pair individually.

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [July 19, 2023, 5:07pm UTC](https://discourse.julialang.org/t/calculating-the-3d-volume-between-arbitrary-planes/101793/4 "2023-07-19T17:07:45Z")

</div>

Ok, if you have the data as a sequence of quadrilaterals, you could compute the volume between them as tetrahedrons … sort of like in [this SO question](https://math.stackexchange.com/questions/1142331/is-there-formula-for-the-volume-of-a-hexahedron). I could probably hack something together if the information in the link is unclear.

EDIT: This [OSTI link](https://www.osti.gov/servlets/purl/632793) has the formulas in it as well.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [July 19, 2023, 6:44pm UTC](https://discourse.julialang.org/t/calculating-the-3d-volume-between-arbitrary-planes/101793/5 "2023-07-19T18:44:36Z")

</div>

You can also create a Meshes.jl `Hexahedron` and ask for the `volume`.

---

<div class="post-metadata">

**Author:** ![Gavin\_Held](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gavin_held/32/49350_2.png) [@Gavin\_Held](https://discourse.julialang.org/u/Gavin_Held)\
**Post date:** [July 19, 2023, 8:07pm UTC](https://discourse.julialang.org/t/calculating-the-3d-volume-between-arbitrary-planes/101793/6 "2023-07-19T20:07:59Z")

</div>

So using meshes looks like it might work, but when I use Hexahedron(planeCornerPoints) I get this weird gap in the mesh:

 ![Screenshot from 2023-07-19 14-59-57](https://global.discourse-cdn.com/julialang/original/3X/f/3/f3b79e85ea1848198291218ad12481f02c0fb76b.png)  
The little gray dots are the points I’m using vertices. Getting the volume is then as simple as doing: measure(Hexahedron(planeCornerPoints)).  
Not sure if this is a visual bug…

---

<div class="post-metadata">

**Author:** ![Gavin\_Held](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gavin_held/32/49350_2.png) [@Gavin\_Held](https://discourse.julialang.org/u/Gavin_Held)\
**Post date:** [July 19, 2023, 8:09pm UTC](https://discourse.julialang.org/t/calculating-the-3d-volume-between-arbitrary-planes/101793/7 "2023-07-19T20:09:49Z")

</div>

This might work, but I am feeling lazy and have already poured a lot of work into a package that’s purpose has very little to do with this. So I was just hoping to use some pre-built julia package. I think Meshes.jl might be a good solution.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [July 19, 2023, 8:29pm UTC](https://discourse.julialang.org/t/calculating-the-3d-volume-between-arbitrary-planes/101793/8 "2023-07-19T20:29:49Z")

</div>

Pay attention to the expected order of vertices in the Hexahedron constructor. Check the examples and tests.

---

<div class="post-metadata">

**Author:** ![Gavin\_Held](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gavin_held/32/49350_2.png) [@Gavin\_Held](https://discourse.julialang.org/u/Gavin_Held)\
**Post date:** [July 19, 2023, 8:39pm UTC](https://discourse.julialang.org/t/calculating-the-3d-volume-between-arbitrary-planes/101793/9 "2023-07-19T20:39:10Z")

</div>

![Screenshot from 2023-07-19 15-38-23](https://global.discourse-cdn.com/julialang/original/3X/b/7/b731df167c320d650296265f19eea930131da0b4.png)  
yes, that worked perfectly, thank you.
