I select 4 points from the image displayed by Kinect, because each point has its own coordinates (x, y, z).
My goal is to determine if 4 points fall on the same plane.
This is my function:
public bool isValidPlane()
{
for (int i = 0; i < edgesPoints.Length; i++)
{
double absPlaneEquation = Math.Abs(distance -
(normal.X * edgesPoints[i].X + normal.Y * edgesPoints[i].Y + normal.Z * edgesPoints[i].Z));
if (absPlaneEquation > 1500)
{
return false;
}
}
return true;
}
normal It is also normal (the transverse product of two vectors on the plane, which was previously calculated from 3 of 4 selected points) and the plane is normalized:
private void calcPlaneNormalVector()
{
if (lastEdgeNumber < 3)
{
return;
}
Vector3D vec1 = new Vector3D(edgesPoints[0], edgesPoints[1]);
Vector3D vec2 = new Vector3D(edgesPoints[0], edgesPoints[2]);
vec2 = vec1.crossProduct(vec2);
double lengthNormal = Math.Sqrt(Math.Pow(vec2.X, 2) + Math.Pow(vec2.Y, 2) + Math.Pow(vec2.Z, 2));
normal = new Vector3D((vec2.X / lengthNormal), (vec2.Y / lengthNormal), (vec2.Z / lengthNormal));
distance = (-1) * (edgesPoints[0].X * normal.X + edgesPoints[0].Y * normal.Y + edgesPoints[0].Z + normal.Z);
}
Vector3D is a class representing a vector:
public class Vector3D
{
private double x, y, z;
public Vector3D(Point3D p1, Point3D p2)
{
x = p2.X - p1.X;
y = p2.Y - p1.Y;
z = p2.Z - p1.Z;
}
public Vector3D(double a = 0, double b = 0, double c = 0)
{
x = a;
y = b;
z = c;
}
<get properties for x, y, z >
public Vector3D crossProduct(Vector3D u)
{
double tmpX = 0, tmpY = 0, tmpZ = 0;
tmpX = y * u.Z - z * u.Y;
tmpY = z * u.X - x * u.Z;
tmpZ = x * u.Y - y * u.X;
return new Vector3D(tmpX, tmpY, tmpZ);
}
public double dotProduct(Vector3D u)
{
return x * u.X + y * u.Y + z * u.Z;
}
}
i always turns out 1300 <= absPlaneEquation <= 1400, even when 4 points are chosen so that they will not be on the same plane.
What is the best way to determine that 4 points are on the same plane?