Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

C#
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.
Posted
Updated 19-Dec-16 3:25am
v3
Comments
CPallini 19-Dec-16 5:22am    
I don't get you: the floor has heights, good. There is a sphere coming down, good. What's the role of the cubes?
AndreTrollip 19-Dec-16 5:57am    
Sorry I should have been clearer on that. Let me remove the cube confusion. The floor consists of equally sized 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 at x, y. The top left corner of the rectangle is defined by x - (cellWidth / 2) and y - (cellHeight / 2). The bottom right corner of the rectangle is defined by x + (cellwidth / 2) and y + (cellHeight / 2)
Patrice T 19-Dec-16 8:57am    
Use Improve question to update your question.
AndreTrollip 19-Dec-16 9:10am    
Done. Thanks.
Patrice T 19-Dec-16 9:31am    
This is not a programming problem, this is basic geometry.
What is your problem with computing the distance between a 3D point and a sphere ?

1 solution

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
So have a go, do some research, do some thinking: but just posting up minimal code and "???" where all the work takes place is not "trying to do it yourself" at all.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
Comments
OriginalGriff 19-Dec-16 5:37am    
So what have *you* done to solve it?
OriginalGriff 19-Dec-16 5:47am    
Oh dear ... I wish you hadn't said that.
Please, don't use abusive language: you have been here long enough to know that isn't allowed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900