I need to generate random coplanar points in a 3-D space. The plane equation is:
a*x + b*y + c*z = d
I generate the plane by randomizing a, b, c and d. In order to generate random points on this plane, I use this code:
switch(random.nextInt(3))
{
case 0:
{
x = random.nextInt(length);
y = random.nextInt(width);
z = (d - (a*x) - (b*y))/c;
break;
}
case 1:
{
x = random.nextInt(length);
z = random.nextInt(height);
y = (d - (a*x) - (c*z))/b;
break;
}
case 2:
{
y = random.nextInt(width);
z = random.nextInt(height);
x = (d - (b*y) - (c*z))/a;
break;
}
}
But when I use Cayley-Menger Determinant to check if the points are coplanar, the determinant is never equal to zero (i.e. points are not coplanar).
The interesting point is, when I generate points on x = 0 plane, Cayley-Menger determinant works perfectly fine!
Is this a rounding error or something else?
EDIT: length, width and height are integer values.