An Oriented Bounding Box (OBB) Intersection Test

本文详细介绍了使用定向包围盒(OBB)进行三维碰撞检测的方法。包括如何通过分离轴定理来判断两个OBB是否相交,并提供了一个实现OBB重叠测试的示例代码。

http://www.gamasutra.com/features/19991018/Gomez_5.htm 

A drawback of using an axis-aligned bounding box is that it can’t fit rotating geometry very tightly.

On the other hand, an oriented bounding box can be rotated with the objects, fitting the geometry with less volume than an AABB. This requires that the orientation of the box must also be specified. Figure 8 shows a 2D example, where A1, A2, B1 and B2 are the local axes of boxes A and B.

 

 

 

 

 

For OBBs, the separating axis test must be generalized to three dimensions. A box's scalar projection onto a unit vector L creates an interval along the axis defined by L.

 

The radius of the projection of box A onto L is

 

The same is true for B, and L forms a separating axis if

 

Note that L does not have to be a unit vector for this test to work. The boxes A and B are disjoint if none of the 6 principal axes and their 9 cross products form a separating axis. These tests are greatly simplified if T and B’s basis vectors (B1, B2, B3) are transformed into A’s coordinate frame.

An OBB class and an implementation of the OBB overlap test is given in Listing 6 below.

 

Listing 6. An OBB class.

#include "coordinate_frame.h"

 

class OBB : public COORD_FRAME
{

public:

 

VeCTOR E; //extents
OBB( const VECTOR& e ) : E(e)

{}

 

};

 

//check if two oriented bounding boxes overlap
const bool OBBOverlap
(

 

//A
VECTOR& a, //extents
VECTOR& Pa, //position
VECTOR* A, //orthonormal basis

//B
VECTOR& b, //extents
VECTOR& Pb, //position
VECTOR* B //orthonormal basis

 

)

{

 

//translation, in parent frame
VECTOR v = Pb - Pa;

//translation, in A's frame
VECTOR T( v.dot(A[0]), v.dot(A[1]), v.dot(A[2]) );

//B's basis with respect to A's local frame
SCALAR R[3][3];
float ra, rb, t;
long i, k;

//calculate rotation matrix
for( i=0 ; i<3 ; i++ )

 

for( k=0 ; k<3 ; k++ )

 

R[i][k] = A[i].dot(B[k]);

/*ALGORITHM: Use the separating axis test for all 15 potential
separating axes. If a separating
axis could not be found, the two
boxes overlap. */

//A's basis vectors
for( i=0 ; i<3 ; i++ )
{

 

ra = a[i];

rb =
b[0]*fabs(R[i][0]) + b[1]*fabs(R[i][1]) + b[2]*fabs(R[i][2]);

t = fabs( T[i] );

if( t > ra + rb )
return false;

 

}

//B's basis vectors
for( k=0 ; k<3 ; k++ )
{

 

ra =
a[0]*fabs(R[0][k]) + a[1]*fabs(R[1][k]) + a[2]*fabs(R[2][k]);

 

rb = b[k];

t =
fabs( T[0]*R[0][k] + T[1]*R[1][k] +
T[2]*R[2][k] );

if( t > ra + rb )
return false;

 

}

//9 cross products

//L = A0 x B0
ra =
a[1]*fabs(R[2][0]) + a[2]*fabs(R[1][0]);

rb =
b[1]*fabs(R[0][2]) + b[2]*fabs(R[0][1]);

t =
fabs( T[2]*R[1][0] -
T[1]*R[2][0] );

if( t > ra + rb )
return false;

//L = A0 x B1
ra =
a[1]*fabs(R[2][1]) + a[2]*fabs(R[1][1]);

rb =
b[0]*fabs(R[0][2]) + b[2]*fabs(R[0][0]);

t =
fabs( T[2]*R[1][1] -
T[1]*R[2][1] );

if( t > ra + rb )
return false;

//L = A0 x B2
ra =
a[1]*fabs(R[2][2]) + a[2]*fabs(R[1][2]);

rb =
b[0]*fabs(R[0][1]) + b[1]*fabs(R[0][0]);

t =
fabs( T[2]*R[1][2] -
T[1]*R[2][2] );

if( t > ra + rb )
return false;

//L = A1 x B0
ra =
a[0]*fabs(R[2][0]) + a[2]*fabs(R[0][0]);

rb =
b[1]*fabs(R[1][2]) + b[2]*fabs(R[1][1]);

t =
fabs( T[0]*R[2][0] -
T[2]*R[0][0] );

if( t > ra + rb )
return false;

//L = A1 x B1
ra =
a[0]*fabs(R[2][1]) + a[2]*fabs(R[0][1]);

rb =
b[0]*fabs(R[1][2]) + b[2]*fabs(R[1][0]);

t =
fabs( T[0]*R[2][1] -
T[2]*R[0][1] );

if( t > ra + rb )
return false;

//L = A1 x B2
ra =
a[0]*fabs(R[2][2]) + a[2]*fabs(R[0][2]);

rb =
b[0]*fabs(R[1][1]) + b[1]*fabs(R[1][0]);

t =
fabs( T[0]*R[2][2] -
T[2]*R[0][2] );

if( t > ra + rb )
return false;

//L = A2 x B0
ra =
a[0]*fabs(R[1][0]) + a[1]*fabs(R[0][0]);

rb =
b[1]*fabs(R[2][2]) + b[2]*fabs(R[2][1]);

t =
fabs( T[1]*R[0][0] -
T[0]*R[1][0] );

if( t > ra + rb )
return false;

//L = A2 x B1
ra =
a[0]*fabs(R[1][1]) + a[1]*fabs(R[0][1]);

rb =
b[0] *fabs(R[2][2]) + b[2]*fabs(R[2][0]);

t =
fabs( T[1]*R[0][1] -
T[0]*R[1][1] );

if( t > ra + rb )
return false;

//L = A2 x B2
ra =
a[0]*fabs(R[1][2]) + a[1]*fabs(R[0][2]);

rb =
b[0]*fabs(R[2][1]) + b[1]*fabs(R[2][0]);

t =
fabs( T[1]*R[0][2] -
T[0]*R[1][2] );

if( t > ra + rb )
return false;

/*no separating axis found,
the two boxes overlap */

return true;

 

}

 

For a more complete discussion of OBBs and the separating axis test, please see [3]. Some other applications of the separating axis test are given next.

【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值