# 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|

• 本文已收录于以下专栏：

举报原因： 您举报文章：Primitive Collision Detecting (6) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)