项目中需要计算有向包围盒OBB相交的计算,这 是计算机图形学中的基本问题,但是我在Simulink中想实现该计算时发现网上几乎没有matlab下的代码。于是参考网上大牛们的c++和java代码,在matlab中重新写了obb相交探测方法。由于matlab先天的强大矩阵计算能力,matlab下实现其实更加简单。再结合简单的可视化方法,可以直观 的实现生动的视觉效果。
本文是本文第一次在该网站上写blog,也是第一次在网上写blog,水平不足之处还请大牛们多留情啊。
计算obb相交的算法:
obbDec.m文件:
function int = obbDec( A,B )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
%x y width height rotation,x,y are center point coordinates
r=A(5);
vec_A=[cos(r),sin(r);
-sin(r),cos(r)];
r=B(5);
vec_B=[cos(r),sin(r);
-sin(r),cos(r)];
disVec=[B(1)-A(1),B(2)-A(2)];
for n=1:2
if getProjectionRadius(vec_A(n,:),A,vec_A)+getProjectionRadius(vec_A(n,:),B,vec_B)<=abs(disVec*vec_A(n,:)')
int=false;
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
%x y width height rotation,x,y are center point coordinates
r=A(5);
vec_A=[cos(r),sin(r);
-sin(r),cos(r)];
r=B(5);
vec_B=[cos(r),sin(r);
-sin(r),cos(r)];
disVec=[B(1)-A(1),B(2)-A(2)];
for n=1:2
if getProjectionRadius(vec_A(n,:),A,vec_A)+getProjectionRadius(vec_A(n,:),B,vec_B)<=abs(disVec*vec_A(n,:)')
int=false;