private int[] distance(float[,] F, double t)
{
int n = pointSet1.Length;
PointF[] x1 = pointSet1;
PointF[] x2 = pointSet2;
double[] x2tFx1 = new double[n];
for (int i = 0; i < x1.Length; i++)
{
float[] a = x2[i].Multiply(F);
float[] b = new float[] { x1[i].X, x1[i].Y, 1 };
x2tFx1[i] = a.Dot(b);
}
PointF[] p1 = F.TransformPoints(x1);
PointF[] p2 = F.Transpose().TransformPoints(x2);
// Compute the distances
double[] d2 = new double[n];
for (int i = 0; i < n; i++)
{
// Compute the distance as
float ax = p1[i].X;
float ay = p1[i].Y;
float bx = p2[i].X;
float by = p2[i].Y;
d2[i] = (x2tFx1[i] * x2tFx1[i]) / ((ax * ax) + (ay * ay) + (bx * bx) + (by * by));
}
// Find and return the inliers
return Matrix.Find(d2, z => Math.Abs(z) < t);
}