public static double determineCurvingCase(this ICoordinated point, IEnumerable <ICoordinated> otherPoints, double flatnessPlane) { var isConvex = false; var isFlat = false; int left = 0; int right = 0; int Inplane = 0; var neighbours = otherPoints.ToList(); for (int i1 = neighbours.Count - 1; i1 >= 1; i1--) { var nb1 = neighbours[i1]; for (int i2 = i1 - 1; i2 >= 0; i2--) { var nb2 = neighbours[i2]; var plane = new HessePlane(nb1, nb2, point); for (int i4 = 0; i4 < neighbours.Count; i4++) { if (i4 == i1 || i4 == i2) { continue; } var otherNb = neighbours[i4]; var dist = otherNb.DistanceValue(plane); if (Math.Abs(dist) < flatnessPlane) { Inplane++; } else { if (dist < 0) { left++; } else { right++; } } } if (Inplane == 0) { if (left == 0 || right == 0) { isConvex = true; } } else { if (left == 0 || right == 0) { isFlat = true; } } if (isConvex) { break; } } if (isConvex) { break; } } if (isConvex) { return(1); } else if (isFlat) { return(0); } else { return(-1); } }
//public static Vector Subtr(this ICoordinated a, ICoordinated b) //{ // var vector = new Vector(); // vector.X = a.X - b.X; // vector.Y = a.Y - b.Y; // vector.Z = a.Z - b.Z; // return vector; //} public static double DistanceValue(this ICoordinated vector, HessePlane plane) { return(vector.ScalarProduct(plane.NormalVector) - plane.RootDistance); }