# 3D Plane in a discrete domain.

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 (ax+by+cz+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 ax+by+cz+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 ‘|ax+by+c*z+d| < delta’ in order to find a plane with only one layer (one point thick) of points.

Thanks,

Luís Gonçalves

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.

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

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.

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.

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:

``````xx
xxxx
xx
``````

Mine:

``````xxx
xxxx
xxx
``````

It depends on what you want it to look like.

EDIT:
I swapped the two illustrations.

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.