// C# program for the above approach
using System;
class GFG {
// To find the maximum area of triangle
static void maxTriangleArea(int[,] rectangle,
int[,] coordinates,
int numberOfCoordinates)
{
int l1min = Int32.MaxValue, l2min = Int32.MaxValue,
l1max = Int32.MinValue, l2max = Int32.MinValue,
b1min = Int32.MaxValue, b1max = Int32.MinValue,
b2min = Int32.MaxValue, b2max = Int32.MinValue;
int l1Ycoordinate = rectangle[0,1];
int l2Ycoordinate = rectangle[1,1];
int b1Xcoordinate = rectangle[0,0];
int b2Xcoordinate = rectangle[1,0];
// Always consider side parallel
// to x-axis as length and
// side parallel to y-axis as breadth
for (int i = 0; i < numberOfCoordinates; i++) {
// coordinate on l1
if (coordinates[i,1] == l1Ycoordinate) {
l1min = Math.Min(l1min,
coordinates[i,0]);
l1max = Math.Max(l1max,
coordinates[i,0]);
}
// Coordinate on l2
if (coordinates[i,1] == l2Ycoordinate) {
l2min = Math.Min(l2min,
coordinates[i,0]);
l2max = Math.Max(l2max,
coordinates[i,0]);
}
// Coordinate on b1
if (coordinates[i,0] == b1Xcoordinate) {
b1min = Math.Min(b1min,
coordinates[i,1]);
b1max = Math.Max(b1max,
coordinates[i,1]);
}
// Coordinate on b2
if (coordinates[i,0] == b2Xcoordinate) {
b2min = Math.Min(b2min,
coordinates[i,1]);
b2max = Math.Max(b2max,
coordinates[i,1]);
}
}
// Find maximum possible distance
// on length
int maxOfLength = Math.Max(Math.Abs(l1max - l1min),
Math.Abs(l2max - l2min));
// Find maximum possible distance
// on breadth
int maxofBreadth = Math.Max(Math.Abs(b1max - b1min),
Math.Abs(b2max - b2min));
// Calculate result base * height / 2
int result
= Math.Max((maxofBreadth
* (Math.Abs(rectangle[0,0]
- rectangle[1,0]))),
(maxOfLength
* (Math.Abs(rectangle[0,1]
- rectangle[1,1]))))
/ 2;
// Print the result
Console.Write(result);
}
// Driver Code
public static void Main ()
{
// Rectangle with x1, y1 and x2, y2
int[,] rectangle = { { 0, 0 },
{ 6, 6 } };
// Coordinates on sides of given rectangle
int[,] coordinates
= { { 0, 2 }, { 0, 3 }, { 0, 5 },
{ 2, 0 }, { 3, 0 }, { 6, 0 },
{ 6, 4 }, { 1, 6 }, { 6, 6 } };
int numberOfCoordinates
= coordinates.GetLength(0);
maxTriangleArea(rectangle, coordinates,
numberOfCoordinates);
}
}
// This code is contributed by Samim Hossain Mondal.