public static IEnumerable <Point3D> FillTriangle(List <Point3D> vertices) { vertices.Sort((x, y) => Ut.F(x.Y - y.Y)); var p1 = vertices[0]; var p2 = vertices[1]; var p3 = vertices[2]; double dP1P2, dP1P3; if (p2.Y - p1.Y > 0) { dP1P2 = (p2.X - p1.X) / (p2.Y - p1.Y); } else { dP1P2 = 0; } if (p3.Y - p1.Y > 0) { dP1P3 = (p3.X - p1.X) / (p3.Y - p1.Y); } else { dP1P3 = 0; } if (dP1P2 > dP1P3) { for (var y = (int)p1.Y; y <= (int)p3.Y; y++) { if (y < p2.Y) { foreach (var p in ProcessScanLine(y, p1, p3, p1, p2)) { yield return(p); } } else { foreach (var p in ProcessScanLine(y, p1, p3, p2, p3)) { yield return(p); } } } } else { for (var y = (int)p1.Y; y <= (int)p3.Y; y++) { if (y < p2.Y) { foreach (var p in ProcessScanLine(y, p1, p2, p1, p3)) { yield return(p); } } else { foreach (var p in ProcessScanLine(y, p2, p3, p1, p3)) { yield return(p); } } } } }