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.
Having three points
P0, P1, P2, we can use two vectorsand get normal using vector product:
Ncomponents are integers. Then calculate GCD (greatest common divisor) ofNx, Ny, Nzand divide components to make them mutually prime (if this ter, is applicable to three values, perhaps "irreducible")and finally find 4th component of general plane equation substituting any point components (say
P0) into equationDefinitely
Dis 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
Pbelongs to given plane.