# Incorrect boundary of the intersection between two hexahedrons

**URL:** https://discourse.vtk.org/t/incorrect-boundary-of-the-intersection-between-two-hexahedrons/3781
**Category:** Support
**Created:** [July 15, 2020, 6:02pm UTC](https://discourse.vtk.org/t/incorrect-boundary-of-the-intersection-between-two-hexahedrons/3781 "2020-07-15T18:02:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![rodrigomologni](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@rodrigomologni](https://discourse.vtk.org/u/rodrigomologni)
#### Post date: [July 15, 2020, 6:02pm UTC](https://discourse.vtk.org/t/incorrect-boundary-of-the-intersection-between-two-hexahedrons/3781/1 "2020-07-15T18:02:29Z")

</div>

Would anyone know how to solve this problem, please?

I am using the `vtkBooleanOperationPolyDataFilter` class to produce the boundary of the intersection between two hexahedrons. Both hexahedrons are triangulated surfaces as required by this class.

The first hexahedron (white) is defined by the following corners:

```auto
corners_1 = [
    (0, 0, 0), (300, 0, 0), (300, 300, 0), (0, 300, 0),
    (0, 0, 100), (300, 0, 100), (300, 300, 100), (0, 300, 100)
]

```

And the second hexahedron (red) is defined by the following corners:

```auto
corners_2 = [
    (200, 200, z), (400, 200, z), (400, 400, z), (200, 400, z),
    (200, 200, 90), (400, 200, 90), (400, 400, 90), (200, 400, 90)
]

```

When I use `z = 30`, the `vtkBooleanOperationPolyDataFilter` class produces a correct result:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/5/5f81f7d609e185aad3f68b347438fbd4c84ddd43.png)

But when I use `z = 40`, this class produces an incorrect result:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/a/a682cd6d0f58b9f497bf36e582885e9379c41ee9.png)

Why is this happening? How can I solve this problem? If anyone can help me, I will be grateful.

My code: [intersection.pyw](https://discourse.vtk.org/uploads/short-url/pPWuE7j9jPIkACgXW8H9KySgBjd.pyw) (2.1 KB)

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [July 16, 2020, 5:41pm UTC](https://discourse.vtk.org/t/incorrect-boundary-of-the-intersection-between-two-hexahedrons/3781/2 "2020-07-16T17:41:11Z")

</div>

VTK’s built-in Boolean operators are known to suffer from these kind of problems, but the [vtkbool remote module](https://github.com/zippy84/vtkbool/blob/master/README.md) is supposed to work well.

---

<div class="post-metadata">

### Author: ![rodrigomologni](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@rodrigomologni](https://discourse.vtk.org/u/rodrigomologni)
#### Post date: [July 16, 2020, 6:43pm UTC](https://discourse.vtk.org/t/incorrect-boundary-of-the-intersection-between-two-hexahedrons/3781/3 "2020-07-16T18:43:56Z")

</div>

@lassoan, thank you! 🙏 🙂

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [July 20, 2020, 3:08pm UTC](https://discourse.vtk.org/t/incorrect-boundary-of-the-intersection-between-two-hexahedrons/3781/4 "2020-07-20T15:08:14Z")

</div>

Hello,

Check whether your geometry meets the requirements to work well with `vtkBooleanOperationPolyDataFilter`:

Quoting the documentation ([VTK: vtkBooleanOperationPolyDataFilter Class Reference](https://vtk.org/doc/nightly/html/classvtkBooleanOperationPolyDataFilter.html)):

> Computes the boundary of the union, intersection, or difference volume computed from the volumes defined by two input surfaces. **The two surfaces do not need to be manifold, but if they are not, unexpected results may be obtained**. The resulting surface is available in the first output of the filter. The second output contains a set of polylines that represent the intersection between the two input surfaces.
> 
> Warning  
> This filter is not designed to perform 2D boolean operations, and in fact **relies on the inputs having no co-planar, overlapping cells**.

(emphasis added)

regards,

Paulo

---

<div class="post-metadata">

### Author: ![rodrigomologni](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@rodrigomologni](https://discourse.vtk.org/u/rodrigomologni)
#### Post date: [July 20, 2020, 3:26pm UTC](https://discourse.vtk.org/t/incorrect-boundary-of-the-intersection-between-two-hexahedrons/3781/5 "2020-07-20T15:26:51Z")

</div>

Hi @Paulo_Carvalho, both hexahedrons meet the requirements of the `vtkBooleanOperationPolyDataFilter` class. Thank you.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [July 20, 2020, 3:34pm UTC](https://discourse.vtk.org/t/incorrect-boundary-of-the-intersection-between-two-hexahedrons/3781/6 "2020-07-20T15:34:31Z")

</div>

We experienced many times that VTK’s Boolean operations fail for completely valid inputs. We ended up doing all Boolean operations by converting meshes to binary labelmaps, but for certain tasks it would be much better to work directly on meshes.

It would be nice if vtkbool module could be available Python, so that we could easily give it a try. By any chance, is it already available in PyPI?

---

<div class="post-metadata">

### Author: ![rodrigomologni](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@rodrigomologni](https://discourse.vtk.org/u/rodrigomologni)
#### Post date: [July 20, 2020, 3:59pm UTC](https://discourse.vtk.org/t/incorrect-boundary-of-the-intersection-between-two-hexahedrons/3781/7 "2020-07-20T15:59:45Z")

</div>

Hi @lassoan! Converting meshes to binary labelmaps? Hummm… an interesting solution! 🤔 Unfortunately, `vtkbool` is not available in PyPI and [https://www.lfd.uci.edu/~gohlke/pythonlibs/](https://www.lfd.uci.edu/~gohlke/pythonlibs/). I’m building VTK and `vtkbool` now. 😉
