public static List <IDFFile.XYZ> TriangulateAndGetCenterOfMass(List <IDFFile.XYZ> AllPoints) { int[] PointNumbers = Enumerable.Range(-1, AllPoints.Count() + 2).ToArray(); PointNumbers[0] = AllPoints.Count() - 1; PointNumbers[PointNumbers.Length - 1] = 0; List <IDFFile.XYZ> CentersOfMass = new List <IDFFile.XYZ>(); for (int i = 0; i < AllPoints.Count(); i++) { IDFFile.XYZ pointCM = new IDFFile.XYZ(); try { pointCM = CenterOfMass(new List <IDFFile.XYZ>() { AllPoints[i - 1], AllPoints[i], AllPoints[i + 1] }); } catch { try { pointCM = CenterOfMass(new List <IDFFile.XYZ>() { AllPoints.Last(), AllPoints[i], AllPoints[i + 1] }); } catch { pointCM = CenterOfMass(new List <IDFFile.XYZ>() { AllPoints[i - 1], AllPoints[i], AllPoints.First() }); } } CentersOfMass.Add(pointCM); } CentersOfMass.Add(CenterOfMass(AllPoints)); return(CentersOfMass); }
public static bool RayCastToCheckIfIsInside(List <Tuple <IDFFile.XYZ, IDFFile.XYZ> > EdgeArrayForPossibleWall, IDFFile.XYZ CM) { int count = 0; foreach (Tuple <IDFFile.XYZ, IDFFile.XYZ> EdgeOfWall in EdgeArrayForPossibleWall) { double r = (CM.Y - EdgeOfWall.Item2.Y) / (EdgeOfWall.Item1.Y - EdgeOfWall.Item2.Y); if (r > 0 && r < 1) { double Xvalue = r * (EdgeOfWall.Item1.X - EdgeOfWall.Item2.X) + EdgeOfWall.Item2.X; if (CM.X < Xvalue) { count++; } } } if (count % 2 == 0) { return(false); } else { return(true); } }