Hi, Your question was breaking my heads , here I tried out to find a generic area calculator all you need is to pass co-ordinates and number of sides for your shape ( note in case of circle sides is 1)
I used polygon generic area calculation:
Refer here :
http://www.mathopenref.com/coordpolygonarea.html[
^]
Shape.cs
___________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericAreaCalculator
{
public class Shape
{
public Dictionary<int,int> x;
public Dictionary<int,> y;
public Shape()
{
x = new Dictionary<int,>();
y = new Dictionary<int,>();
}
}
}
Area.cs
_______
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericAreaCalculator
{
public class Area:Shape
{
public float CalculateArea(Shape Shapes,int sides)
{
float area = 0;
int x1 = 0;
int y2 = 0;
int y1 = 0;
int x2 = 0;
if (sides > 1)
{
for (int index = 1; index < sides; index++)
{
x1 = Shapes.x[index];
y2 = Shapes.y[index + 1];
y1 = Shapes.y[index];
x2 = Shapes.x[index + 1];
area = area + (((x1 * y2)) - ((y1 * x2)));
}
int xn = Shapes.x[sides];
y1 = Shapes.y[1];
int yn = Shapes.y[sides];
x1 = Shapes.x[1];
area = (area + (((xn * y1)) - ((yn * x1))))/2;
}
else if (sides == 1)
{
area = (float)(3.14 * Shapes.x[0] * Shapes.x[0]);
}
return Math.Abs(area);
}
}
}
Program.cs
___________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericAreaCalculator
{
class Program
{
static void Main(string[] args)
{
Shape shapeobj = new Shape();
shapeobj.x.Add(1, 0);
shapeobj.x.Add(2, 10);
shapeobj.x.Add(3, 10);
shapeobj.x.Add(4, 0);
shapeobj.y.Add(1, 0);
shapeobj.y.Add(2, 0);
shapeobj.y.Add(3, 10);
shapeobj.y.Add(4, 10);
Area area = new Area();
float ShapeArea = area.CalculateArea(shapeobj, 4);
}
}
}
Note : Here Index of Co-ordinates have much importance , Make it in sequence