由具有整数坐标的 3 个点定义的平面的明确可哈希表示
我需要能够使用平面作为哈希图中的键。这些平面由 3d 空间中的三个不同点定义。我一直无法找到平面的表示,无论使用平面上的哪些点来构造它,它都是相同的,因此可以对它进行哈希处理。平面方程已被淘汰,因为它会导致使用不精确的浮点。
可以在没有这种表示的情况下实现相等比较,但理想情况下,不需要特殊的逻辑。
问题是如何获得由三个点定义的平面的明确的可散列表示,这三个点具有整数坐标;或者失败了这样一个平面的哈希函数。代表同一平面的其他三个点应该具有相同的哈希码。
我正在使用 Rust,但伪代码没问题。性能是一个问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有了三个点
P0、P1、P2
,我们可以使用两个向量并使用向量积得到法线:
N
个分量是整数。然后计算Nx、Ny、Nz
的GCD(最大公约数)并除以使它们互质(如果这个三者适用于三个值,也许“不可约”),最后找到第4个分量一般平面方程的任意点分量(例如
P0
)代入方程肯定
D
是整数,所有系数互质/不可约,所以元组(A,B,C,D)
是一种“归一化”平面方程。该方程和任何具有比例系数的方程都表示同一平面,并且可用于检查某个点
P
是否属于给定平面。Having three points
P0, P1, P2
, we can use two vectorsand get normal using vector product:
N
components are integers. Then calculate GCD (greatest common divisor) ofNx, Ny, Nz
and 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
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.