using System.Collections.Generic;
using static System.Math;
using NetTopologySuite.Geometries;
using static NetTopologySuite.Algorithm.AngleUtility;
public static void Main()
var questionOne = CheckArea();
var questionTwo = isColumInTerrain();
var questionThree = spaceBetweenColumns();
var questionFour = CheckIfColumnIsRectangular();
for(int i=0;i<questionOne.Count;i++)
Console.WriteLine("Question 1 : Column " + i + " comply with maximum area? " + questionOne[i]);
for(int i=0;i<questionTwo.Count;i++)
Console.WriteLine("Question 2 : Column " + i + " is inside terrain? " + questionTwo[i]);
for(int i=0;i<questionThree.Count;i++)
Console.WriteLine("Question 3 : Column " + i + " have 7m distance to all columns? " + questionThree[i]);
for(int i=0;i<questionFour.Count;i++)
Console.WriteLine("Question 4 : Column " + i + " in rectangular? " + questionFour[i]);
public static Polygon CreatePolygon(double[] xValues, double[] yValues)
var coordinates = new List<Coordinate>();
for (int i = 0; i < xValues.Length; i++)
coordinates.Add(new Coordinate(xValues[i], yValues[i]));
var ring = new LinearRing(coordinates.ToArray());
return new Polygon(ring);
public static List<Polygon> LoadColumns()
var columns = new List<Polygon>();
columns.Add(CreatePolygon(new[] { 2.0, 6.0, 6.0, 2.0, 2.0 }, new[] { 3.0, 3.0, 5.0, 5.0, 3.0 }));
columns.Add(CreatePolygon(new[] { 9.0, 12.0, 10.0, 7.0, 9.0 }, new[] { 5.0, 8.0, 10.0, 7.0, 5.0 }));
columns.Add(CreatePolygon(new[] { 17.0, 17.0, 19.0, 19.0, 17.0 }, new[] { 1.0, -3.0, -3.0, 1.0, 1.0 }));
columns.Add(CreatePolygon(new[] { 19.0, 19.0, 24.0, 24.0, 19.0 }, new[] { 8.0, 5.0, 5.0, 6.0, 8.0 }));
public static Polygon LoadTerrain()
return CreatePolygon(new[] { 1.0, 28.0, 23.0, -1.0, 1.0 }, new[] { 9.0, 9.0, -6.0, -2.0, 9.0 });
public static List<bool> CheckArea()
List<Polygon> columns = LoadColumns();
List<bool> result = new List<bool>();
foreach(var column in columns)
if(column.Area > maxArea)
public static List<bool> isColumInTerrain()
List<Polygon> columns = LoadColumns();
Polygon terrain = LoadTerrain();
List<bool> result = new List<bool>();
foreach(var column in columns)
terrain.Contains(column);
public static List<bool> spaceBetweenColumns()
List<Polygon> columns = LoadColumns();
double minDistance = 7.0;
List<bool> result = new List<bool>();
for (int i = 0; i < columns.Count; i++)
bool comparisonResult = true;
for (int j = 0; j < columns.Count; j++)
double distance = columns[i].Distance(columns[j]);
if (distance < minDistance)
comparisonResult = false;
result.Add(comparisonResult);
public static List<bool> CheckIfColumnIsRectangular ()
List<Polygon> columns = LoadColumns();
List<bool> result = new List<bool>();
double straightAngle = 90;
foreach(var column in columns)
var coordinates = column.Coordinates;
bool isRectangular = true;
if (coordinates.Length == 5)
for (int i = 0; i < coordinates.Length; i++)
Coordinate coord = coordinates[i];
Coordinate nextCoord = coordinates[(i+1)%4];
Coordinate beforeCoord = coordinates[(i+3)%4];
double angle = AngleBetween(beforeCoord, coord, nextCoord)*(180/Math.PI);
if (angle != straightAngle)
result.Add(isRectangular);
result.Add(isRectangular);