Collision detection between two general hexahedrons

前端 未结 3 832
萌比男神i
萌比男神i 2020-12-18 17:16

I have 2 six faced solids. The only guarantee is that they each have 8 vertex3f\'s (verticies with x,y and z components). Given this, how can I find out if these are collidi

3条回答
  •  误落风尘
    2020-12-18 17:44

    It seems I'm too dumb to quit.

    Consider this. If any edge of solid 1 intersects any face of solid 2, you have a collision. That's not quite comprehensive because there are case when one is is fully contained in the other, which you can test by determining if the center of either is contained in the other.


    Checking edge face intersection works like this.

    1. Define the edge as vector starting from one vertex running to the other. Take note of the length, L, of the edge.
    2. Define the plane segments by a vertex, a normal, an in-plane basis, and the positions of the remaining vertices in that basis.
    3. Find the intersection of the line and the plane. In the usual formulation you will be able to get both the length along the line, and the in-plane coordinates of the intersection in the basis that you have chosen.
    4. The intersection must line as length [0,L], and must lie inside the figure in the plane. That last part is a little harder, but has a well known general solution.

    This will work. For eloquence, I rather prefer R..'s solution. If you need speed...well, you'll just have to try them and see.

提交回复
热议问题