用数学方法算基元碰撞检测 (6)

Sphere & AABB

Sphere:   | P – C | <= R

AABB :A  { V3d inf, sup;}

 

           //摘自Real Time Rendering

 

           d = 0;

           for each i [x, y, z]

            {

               if ( C.i < A.inf.i )

              {

              d += (C.i –A.inf.i)^2;
              }

              else

              if ( C.i > A.sup.i )

              {

              d += (C.i –A.sup.i)^2;
               }

           }

 

 if ( d > R^2 )return No Intersection;

 

           return Intersectant;

 

 

Sphere & OBB

Sphere:   | P – Q | <= R

OBB :     {  V3d C, U, V, W;

  V3d L; }      //C是中心点坐标,U、V、W是三个轴方向,L的三个分量是U、V、W是三个方向的半长,表示Box长宽高各一半大小

 

Method(1)

             做空间变换,使得变成Sphere & AABB的相交判断,这种做法是Real Time Rendering上写的

 

Method(2)

             S = Q – C;

             x = S • U;

             y = S • V;

             z = S • W;

 

      d = 0;

       for each i [x, y, z]

{

          if ( i < -L.i )

{

              d += (i + L.i)^2;

}

           else

          if (i > L.i )

{

              d += (i –L.i)^2;

}

}

 

      if ( d > R^2 )return No Intersection;

 

       return Intersectant;

 

Ellipsoid & AABB

Ellipsoid:    (x - x0)^2 / a^2 + (y - y0)^2 / b^2 + (z - z0)^2 / c^2 <= 1       (a>0, b>0, c>0)

AABB   :  A  { V3d inf, sup;}

 

Method(1)

                    做空间变换,将Ellipsoid变换成Sphere,然后做Sphere & AABB的相交判断

 

Method(2)

                    P0 = { x0, y0, z0 };

           d = 0;

           for each i [x, y, z], j ∈ [a, b, c]

           {

              if ( P0.i < A.inf.i )

               {

              d += (P0.i –A.inf.i)^2 / j^2;
              }

               else

              if ( P0.i > A.sup.i )

              {

              d += (P0.i –A.sup.i)^2 / j^2;
              }

            }

 

 if ( d > 1 )  return No Intersection;

 

           return Intersectant;

 

Ellipsoid& OBB

Ellipsoid:    (x - x0)^2 / a^2 + (y - y0)^2 / b^2 + (z - z0)^2 / c^2 <= 1       (a>0, b>0, c>0)

OBB   :  {  V3d C, U, V, W;

  V3d L; }

 

Method(1)

                    做空间变换,将Ellipsoid变换成Sphere,然后做Sphere & OBB 的相交判断

 

Method(2)

                    做空间变换,将OBB变换成AABB,然后做Ellipsoid & AABB的相交判断

 

Method(3)

                    做两次空间变换,将Ellipsoid变换成Sphere,OBB变换成AABB,然后做Sphere & AABB的相交判断

 

Method(4)

             P0 = { x0, y0, z0 };

             S = P0 – C;

             x = S • U;

             y = S • V;

             z = S • W;

 

       d = 0;

       for each i [x, y, z], j ∈ [a, b, c]

{

          if ( i < -L.i )

{

              d += (i + L.i)^2 / j^2;

}

          else

          if ( i > L.i )

{

              d += (i –L.i)^2 / j^2;

}

}

 

       if ( d > 1 )  return No Intersection;

 

return Intersectant;

 

 

Line Segment & Sphere, Optimized

Line Seg:  P = P0 + t * V         t ∈ [0, 1]

Sphere :  | P – C | <= R

 

//摘自Real Time Rendering

          L = C – P0;

s = V • L / |V|;

l2 = L^2;

if ( s < 0 && l2 > r^2 )   return No Intersection;

 

m2 = l2 – s^2;

if ( m2 > r^2 )           return No Intersection;

 

returnIntersectant;

//q = sqrt(r^2 – m^2);

//if ( l^2 > r^2 ) t = (s – q) / |V|;

//elset = (s + q) / |V|

           



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值