我有一组点的坐标(X,Y,Z)。我需要检查它们是否在某种公差范围内共面。我的方法是:将所有点从全局坐标系转换到本地坐标系,其中本地x,y在由集合中的3个点定义的平面上,z垂直于该平面。然后,我只需要检查集合中的所有点是否具有大致相似的本地z值。
但是,棘手的部分是如何选择3个点来定义参考平面。如果随机选择,这将导致有时点集共面,有时不共面。您有什么建议吗?
但是,棘手的部分是如何选择3个点来定义参考平面。如果随机选择,这将导致有时点集共面,有时不共面。您有什么建议吗?
可能最常见的方法是使用主成分分析:https://en.wikipedia.org/wiki/Principal_component_analysis
简单描述如下:
normal n
pick any 3 points from your dataset that are not on a single line let call them p0,p1,p2
. To improve accuracy they should be more distant to each other. Now to construct a normal vector do this:
n = cross( p1-p0 , p2-p0 ); // perpendicular vector to both operands of cross
n /= |n|; // unit vector
check all points
for any point on the plane formed by p0,p1,p2
the altitude
component (in normal direction) should be zero so for any point p
:
|dot( p-p0 , n )|<=1e-10
the 1e-10
is just some zero threshold due to accuracy loss on FPU ... Any point not satisfying the condition does not belong to the plane ...