public void FindExtendIndices(PointD A, PointD B, out int one, out int two) { double leftdistance = 0; double rightdistance = 0; int leftindex = 0; int rightindex = 0; for (int i = 0; i < Shape.Count(); i++) { PointD C = new PointD(Shape.Vertices[i].X + A.X, Shape.Vertices[i].Y + A.Y); //bool side = isLeft(A, B, C); double dist = (double)PointD.CrossProduct(A, B, C); if (dist > 0) { if (rightdistance < dist) { rightdistance = dist; rightindex = i; } ; } else { dist = -dist; if (leftdistance < dist) { leftdistance = dist; leftindex = i; } ; } } two = leftindex; one = rightindex; }