确定球体和矩形的最高碰撞点 [英] Determine highest collision point of a sphere and rectangles

查看:98
本文介绍了确定球体和矩形的最高碰撞点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代表地板的2D高度矩阵。



地板由同样大小的轴对齐矩形组成,平行于XY平面,在不同的高度(z)。我用2D矩阵(Matrix [x,y])表示地板,这样每个反应角的z是x,y矩阵中的元素。矩形的左上角由x和y定义。矩形的右下角由x + cellWidth和y + cellHeight定义。



我也有一个球体。当球体落到地板上时,我需要确定球体与任何矩形碰撞的第一个点(作为球体的中心)。球体将始终位于矩形的中心。



可以使用Matrix [x,y]访问矩阵元素,这将返回矩形的高度x,y作为小数。



GetFootprintFromTopView仅仅是因为我可以剪切到受影响的地板空间而不是检查所有地板矩形。



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.

推荐答案

我们不做你的作业:它是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。

所以有一个去做,做一些研究,做一些思考:但只是张贴最小代码和???所有工作都不是自己动手做。



亲自尝试一下,你可能会发现它并不像你想象的那么难!



如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!
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!


这篇关于确定球体和矩形的最高碰撞点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆