I have a rectangular mesh that is represented as a bidimensional array of bidimensional points. Something like this (C#-inspired pseudo-code):
Point2D[,] mesh = CreateSampleMesh();
mesh.Plot();
Important characteristics are:
- The mesh is topologically rectangular, but geometrically "irregular" as the image shows;
- The X coordinate of each row and Y coordinate of each column is monotonical (that is, it does not "reverse directions");
- Every rectangle is convex (a necessary consequence of item 2, I guess);
My question is: given a candidate Point2D, how do I find which " rectangle" it's inside, if any? Here is the method signature I would suggest:
GridPosition position = GetIndexOfBottomLeftRectangleContaining(Point2D candidatePoint);
if (position != null)
{
int pi = Position.I;
int pj = Positino.J;
}