public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
double[,] allPoints = new double[5, 3]; //Each rectangle is defined by 4 X/Y Points (left-top, left-bottom, right-top and right-bottom)
//The four points of each rectangle have to be inside the given area (inside the given couple of red lines)
int foundInArea = 0;
int areaCount = 0;
do
{
areaCount = areaCount + 1; //There are three areas; what is inside each couple of two red lines
foundInArea = areaCount;
int count1 = 0;
do
{
count1 = count1 + 1;
if (!isInArea(areaCount, new double[] { 0, allPoints[count1, 1], allPoints[count1, 2] }))
{
foundInArea = 0;
break;
}
} while (count1 < 4);
if (foundInArea > 0)
{
break;
}
} while (areaCount < 3);
if (foundInArea > 0)
{
//Rectangle inside are foundInArea
}
}
private bool isInArea(int areaNo, double[] pointToTest)
{
bool isThere = false;
double alpha = returnAngles(areaNo); //Inclination of the red lines
double[] startPoint1 = returnStartEndPoints(areaNo, true, true); //Initial point of the red line on the left
double[] endPoint1 = returnStartEndPoints(areaNo, true, false); //End point of the red line on the left
double[] startPoint2 = returnStartEndPoints(areaNo, false, true); //Initial point of the red line on the right
double[] endPoint2 = returnStartEndPoints(areaNo, false, false); //End point of the red line on the right
return checkPoint(pointToTest, alpha, startPoint1, endPoint1, startPoint2, endPoint2);
}
private bool checkPoint(double[] pointToTest, double alpha, double[] startPoint1, double[] endPoint1, double[] startPoint2, double[] endPoint2)
{
bool isThere = false;
//You have all the information and can perform the required trigonometrical calculculations to determine whether the two lines surround the given point or not
//I think that I have worked more than enough in this code :)
return isThere;
}
//Hardcoded angles for each red line.
//All the angles have to be taken from the same reference point (for example: middle-bottom part)
//Example: area1 (lines on the left): 240 degree, area2: 270 degree...
private double returnAngles(int areaNo)
{
double outVal = 0;
if (areaNo == 1)
{
//outVal = val;
}
else if (areaNo == 2)
{
//outVal = val;
}
else if (areaNo == 3)
{
//outVal = val;
}
return outVal;
}
//Returning the X (index 1) and Y (index 2) values under the given conditions (start/end point for each area)
//These values have to be hardcoded from a rough estimation. For example, by assuming that the start is in the upper part,
//the starting point for the left line can be assumed to be X = max_X/3 and Y = max_Y
private double[] returnStartEndPoints(int areaNo, bool isLeftLine, bool isStartPoint)
{
double[] outPoint = new double[3];
if (areaNo == 1)
{
if (isLeftLine)
{
if (isStartPoint)
{
//outPoint[1] = value; //hardcoded X for start point of line on the left of area1
//outPoint[2] = value; //hardcoded Y for start point of line on the left of area1
}
else
{
//outPoint[1] = value;
//outPoint[2] = value;
}
}
else
{
if (isStartPoint)
{
//outPoint[1] = value;
//outPoint[2] = value;
}
else
{
//outPoint[1] = value;
//outPoint[2] = value;
}
}
}
else if (areaNo == 2)
{
if (isLeftLine)
{
if (isStartPoint)
{
//outPoint[1] = value;
//outPoint[2] = value;
}
else
{
//outPoint[1] = value;
//outPoint[2] = value;
}
}
else
{
if (isStartPoint)
{
//outPoint[1] = value;
//outPoint[2] = value;
}
else
{
//outPoint[1] = value;
//outPoint[2] = value;
}
}
}
else if (areaNo == 3)
{
if (isLeftLine)
{
if (isStartPoint)
{
//outPoint[1] = value;
//outPoint[2] = value;
}
else
{
//outPoint[1] = value;
//outPoint[2] = value;
}
}
else
{
if (isStartPoint)
{
//outPoint[1] = value;
//outPoint[2] = value;
}
else
{
//outPoint[1] = value;
//outPoint[2] = value;
}
}
}
return outPoint;
}
}