Collision detection between two general hexahedrons

前端 未结 3 834
萌比男神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:41

    I'm hesitant to answer after you deleted your last question while I was trying to answer it and made me lose my post. Please don't do that again. Anyway:

    Not necessarily optimal, but obviously correct, based on constructive solid geometry:

    1. Represent the two solids each as an intersection of 6 half-spaces. Note that this depends on convexity but nothing else, and extends to solids with more sides. My preferred representation for halfspaces is to choose a point on each surface (for example, a vertex) and the outward-pointing unit normal vector to that surface.
    2. Intersect the two solids by treating all 12 half-spaces as the defining half-spaces for a new solid. (This step is purely conceptual and might not involve any actual code.)
    3. Compute the surface/edge representation of the new solid and check that it's non-empty. One approach to doing this is to initially populate your surface/edge representation with one surface for each of the 12 half-spaces with edges outside the bounds of the 2 solids, then intersect its edges with each of the remaining 11 half-spaces.

    It sounds like a bit of work, but there's nothing complicated. Only dot products, cross products (to get the initial representation), and projections.

提交回复
热议问题