I have a 2D matrix of heights representing a "floor".
The floor consists of equally sized, axis-aligned, rectangles, parallel to the XY plane, at different heights (z). I represent the floor with a 2D Matrix (Matrix[x, y]), such that each reactangle's z is the element in the matrix at x, y. The top left corner of the rectangle is defined by x and y. The bottom right corner of the rectangle is defined by x + cellWidth and y + cellHeight.
I also have a sphere. I need to determine the first point (as the centre of the sphere) at which the sphere collides with any of the rectangles, as the sphere comes down onto the floor. The sphere will always come down at the centre of a rectangle.
Matrix elements can be accessed with Matrix[x,y] which will return the height of the rectangle at x,y as a decimal.
The GetFootprintFromTopView is merely so I can clip to the affected "floor space" instead of checking all the floor rectangles.
private decimal sphereDiameter;
decimal DetermineCollisionHeightAt(int x, int y, Matrix heights, decimal cellWidth, decimal cellHeight)
{
var footprintMatrix = GetFootprintFromTopView();
}
Matrix GetFootprintFromTopViewAt(int x, int y, Matrix heights, decimal cellWidth, decimal cellLength)
{
var heightMapLeft = 0;
var heightMapRight = heights.Width - 1;
var heightMapTop = 0;
var heightMapBottom = heights.Length - 1;
var diameter = sphereDiameter;
var radius = diameter / 2;
var centerX = (x * cellWidth) + (cellWidth / 2);
var centerY = (y * cellLength) + (cellLength / 2);
Matrix subMatrixToReturn = null;
return subMatrixToReturn;
}
What I have tried:
The problem is that I have no idea how to approach this. The methods above is what I have so far.