0

I need to be able to use planes as keys in a hash map. The planes are defined by three distinct points in 3d space. I have been unable to find a representation for a plane, that is the same no matter which points on it are used to construct it, so it can be hashed. The plane equation is out since it would lead to the usage of floating points, which are not precise.

Equality comparison can be implemented without such representation but ideally, there should be no need for special logic.

The question is how to obtain an unambiguous hashable representation for a plane defined by three points, which have integer coordinates; or failing that a hash function for such a plane. Other three points that represent the same plane should have the same hashcode.

I am using rust, but pseudo-code is ok. Performance is a concern.

  • Any point belonging to some plane `S`, also belongs to infinite number of another planes, so we **cannot** assign the only hash value to the point itself. – MBo Mar 09 '22 at 03:18
  • @MBo read the question. The plane is defined by three distinct points. For the plane to be unambiguously defined I guess, there is also the requirement, that the points must not fall on the same line. – Topi Karvonen Mar 09 '22 at 07:44
  • Let you have six planes `x=0, y=0, z=0, x-y=0, x+y+2z=0, 3x-2y+z=0`.... Point (0,0,0) should be assigned to.. what one? – MBo Mar 09 '22 at 09:23
  • I've written answer - how to get "normalized in integers" plane equation, but haven't posted it because it doesn't solve hashing problem. – MBo Mar 09 '22 at 09:30
  • @MBo you are confusing coordinates and points. As I said the plane is defined by three distinct points say (x0, y0, z0), (x1, y1, z1), (x2, y2, z3), which do not fall on the same line. – Topi Karvonen Mar 09 '22 at 09:42
  • OK. Look at unambiguous plane representation in my answer. – MBo Mar 09 '22 at 09:45
  • Let f(x,y,z) = ax + by + cz + d. The plane is then defined as f(x0, y0, z0) = 0, f(x1, y1, z1) = 0, f(x2, y2, z2) = 0. – Topi Karvonen Mar 09 '22 at 09:51
  • @MBo the problem with f(x) is that a, b, c, and d are not integer and thus are not precise and hashable. (using floating points) – Topi Karvonen Mar 09 '22 at 09:52
  • For `defined by three points, which have integer coordinates` coefficients a,b,c,d are integers – MBo Mar 09 '22 at 09:55

1 Answers1

1

Having three points P0, P1, P2, we can use two vectors

P10 = P1 - P0
P20 = P2 - P0

and get normal using vector product:

N = P10 x P20

N components are integers. Then calculate GCD (greatest common divisor) of Nx, Ny, Nz and divide components to make them mutually prime (if this ter, is applicable to three values, perhaps "irreducible")

G = GCD(GCD(Nx, Ny), Nz)
A = Nx / G   //integer division
B = Ny / G
C = Nz / G

and finally find 4th component of general plane equation substituting any point components (say P0) into equation

A * P0x + B * P0y + C * P0z + D = 0
D = - (A * P0x + B * P0y + C * P0z)

Definitely D is integer, all coefficients are mutual prime/irreducible, so tuple (A,B,C,D) is a kind of "normalized" plane equation.

Both this equation and any equation with proportional coefficients represents the same plane and might be used to check if some point P belongs to given plane.

if (A * Px + B * Py + C * Pz + D == 0)...
MBo
  • 77,366
  • 5
  • 53
  • 86