# 3D Plane in a discrete domain.

**URL:** https://discourse.vtk.org/t/3d-plane-in-a-discrete-domain/5512
**Category:** Support
**Created:** [April 7, 2021, 1:18pm UTC](https://discourse.vtk.org/t/3d-plane-in-a-discrete-domain/5512 "2021-04-07T13:18:39Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [April 7, 2021, 1:18pm UTC](https://discourse.vtk.org/t/3d-plane-in-a-discrete-domain/5512/1 "2021-04-07T13:18:39Z")

</div>

Dear All,

Perhaps a math question but I think someone in this forum knows.

I have a 3D plane defined by 3 floating points. I determine the plane equation parameters (a_x+b_y+c_z+d=0). I want to test all integer points (x,y,z) of the domain if them are in the plane. I have to verify the equation a_x+b_y+c_z+d=0. But because (x,y,z) are discrete the equation could not be fulfill by any point. How can I find “delta” in order that ‘|a_x+b_y+c\*z+d| \< delta’ in order to find a plane with only one layer (one point thick) of points.

Thanks,

Luís Gonçalves

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [April 7, 2021, 1:31pm UTC](https://discourse.vtk.org/t/3d-plane-in-a-discrete-domain/5512/2 "2021-04-07T13:31:24Z")

</div>

What you could do is fix 2 dimensions, (x, y) for instance, and look where z would fall if it was on the plane, and do it for each dimension. If z is strictly further than 1, then is it not on the plane.

Here’s how to compute the z coordinate on the plane:  
z = - (ax + by + d) / c

A point is on the plane if the test succeeds for all dimensions.

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [April 7, 2021, 1:32pm UTC](https://discourse.vtk.org/t/3d-plane-in-a-discrete-domain/5512/3 "2021-04-07T13:32:31Z")

</div>

I have to add, you have to be careful not to divide by zero, and do special cases when it would happen.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [April 7, 2021, 1:51pm UTC](https://discourse.vtk.org/t/3d-plane-in-a-discrete-domain/5512/4 "2021-04-07T13:51:13Z")

</div>

Let’s define the variable _thickness_ that is equal to your desired selection plane thickness. If the intent is to measure the thickness in the direction perpendicular to the plane, then all you need to do is make that everything is properly scaled:

|_ax_+_by_+_cz_+_d_| \< 0.5\*thickness\*sqrt(_a_^2 + _b_^2 + _c_^2)

Note that if (_a_,_b_,_c_) form a unit vector, then sqrt(_a_^2 + _b_^2 + _c_^2) will be equal to 1.

* * *

As a further note, I think it is best _not_ to use the absolute value. Instead, make two comparisons, one with \< and one with \>=, in order to make the selection inclusive:

_ax_+_by_+_cz_+_d_ \< 0.5\*thickness\*sqrt(_a_^2 + _b_^2 + _c_^2)

and

_ax_+_by_+_cz_+_d_ \>= -0.5\*thickness\*sqrt(_a_^2 + _b_^2 + _c_^2)

This is important if you are trying to select the points in multiple adjacent planes. You need the ‘=’ or else you will miss points that are exactly at the boundary between selection planes.

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [April 7, 2021, 2:22pm UTC](https://discourse.vtk.org/t/3d-plane-in-a-discrete-domain/5512/5 "2021-04-07T14:22:20Z")

</div>

David Gobbi thanks for the theoretical explanation. Certainly it will be useful in the future and it answers right way what I asked.  
I used the Yohann Bearzi suggestion. I was being complicated.

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [April 7, 2021, 2:37pm UTC](https://discourse.vtk.org/t/3d-plane-in-a-discrete-domain/5512/6 "2021-04-07T14:37:14Z")

</div>

The difference between what I suggested and what @dgobbi suggested is that with mine, you have a thickness per axis, whereas with his, you have a thickness relative to the line. Visually, the difference could look like that:

David’s:

```auto
xx
  xxxx
      xx

```

Mine:

```auto
xxx
  xxxx
     xxx

```

It depends on what you want it to look like.

EDIT:  
I swapped the two illustrations.

---

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [April 12, 2021, 8:58pm UTC](https://discourse.vtk.org/t/3d-plane-in-a-discrete-domain/5512/7 "2021-04-12T20:58:24Z")

</div>

Sorry, I think you must swap again the illustrations.  
I wanted to separate one volume with planes and found out that David way isolates better the volume in several. I had to select one point of the one separated volume and select the volume with vtk.vtkImageConnectivityFilter() and found out that your way I selected not only the wanted volume but also the other next. At least with the case tested. That do not happen with David way.  
But I want to thank both.
