4

I have a set of point3D (X, Y, Z). I need to check if they are coplanar with some sort of tolerances. My way of doing it is that: I convert all points from the Global Coordinate System to Local one, where local x,y is in the same plane of the plane defined by 3 points in the set, and z is normal to that plane. And then, all I need to do is to check if all points in the set have approximately similar local z values.

However, the tricky part is how to pick the 3 points to define the reference plane. If picked randomly, this would result in sometimes the set of points are coplanar, sometimes not. Do you have any suggestion?

N.T.C
  • 658
  • 2
  • 9
  • 20

2 Answers2

3

Probably the most common way to do this would be with Principal Component Analysis: https://en.wikipedia.org/wiki/Principal_component_analysis

The short description is:

  1. Calculate the 3x3 covariance matrix of the input points
  2. Extract the smallest Eigenvector. That is the normal vector for the plane that is the Least-Squared-Error fit to all your points.
Matt Timmermans
  • 53,709
  • 3
  • 46
  • 87
1
  1. 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
    
  2. 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 ...

So how to pick 3 points forming a triangle ?

  1. pick p0,p1

    pick p0 as point that has minimal x,y,z coordinates and p1 that has maximal x,y,z coordinates. This ensures they are distant enough.

  2. pick p2

    now sear the points and find such that |dot( p1-p0, pi-p0 )| is minimal. While |pi-p0| is not zero and big enough (for example at least 0.1*|p1-p0|). That ensures the points form a triangle and are not too close to each.

All of this is doable in O(n) so is still fast ...

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Isn't this same as what I described in my question? The problem here is actually what criterion to use to pick p1, p2 and p3. It is quite tricky since, for example, if all points are co-planar but p3, then the pick would result in wrong results. – N.T.C Jan 03 '19 at 08:53
  • @N.T.C Yes youre right sorry I forgot to submit the other part of answer ... silly me :) – Spektre Jan 03 '19 at 08:59