   Tris3Tris3 CollisionDetection using the seperating axis method
  Hello, i have implemented an intersection test for triangles in 3D using the separating axis method. I've made a little simulation in maple but the system detect collision when the 2 triangle are close but not intersecting. I can't find whats wrong  and i thinks its time for a little help, anyone ? Thanks!> with(plottools): with(plots): with(linalg):> TrisProjection:= > proc(axis,tris)> local D, fmin, fmax, ret;> D:=[dotprod(axis,tris[0]),dotprod(axis,tris[1]),dotprod(axis,tris[2])];> fmin:=D[1];> fmax:=fmin;> > if(D[2] < fmin) then> fmin:=D[2];> elif(D[2] > fmax) then> fmax:=D[2];> fi;> > if(D[3] < fmin) then> fmin:=D[3];> elif(D[3] > fmax) then> fmax:=D[3];> fi;> ret:=array(0..1);> ret[0]:=fmin:> ret[1]:=fmax:> ret:> end proc:> frame:=array(0..19):dTime:=0:> for iframe from 0 to 19 do> dTime:=dTime+0.1:> tris1:=array(0..2,[[1+dTime,-0.5,-1],[1.5+dTime,0.5,0],[2+dTime,-0.5,1]]):> tris2:=array(0..2,[[2,0,0],[2.5,1,0],[3,0,0]]):> > tris1Edg:=array(0..2,[tris1[1]-tris1[0], tris1[2]-tris1[1], tris1[0]-tris1[2]] ):> tris2Edg:=array(0..2,[tris2[1]-tris2[0], tris2[2]-tris2[1], tris2[0]-tris2[2]] ):> > tris1N:=normalize(crossprod(tris1[0],tris1[1])):> tris2N:=normalize(crossprod(tris2[0],tris2[1])):> > tris1C:=(tris1[0]+tris1[1]+tris1[2])/3:> tris2C:=(tris2[0]+tris2[1]+tris2[2])/3:> > T1NxT2N:=normalize(crossprod(tris1N,tris2N)):> > dv:=dotprod(tris1N,tris1[0]):> mm1:=TrisProjection(tris1N,tris2):> aMin:=mm1[0]: aMax:=mm1[1]:> > if((dv < aMin) or (dv > aMax)) then> plot_axisFirst:=arrow(tris1C,tris2N,shape=arrow,color=green):> else> plot_axisFirst:=arrow(tris1C,tris2N,shape=arrow,color=red):> fi:> > if( dotprod(T1NxT2N,T1NxT2N) >= Maple_floats(MIN_FLOAT)*((dotprod(tris1N,tris1N)*dotprod(tris2N,tris2N))) ) then> plot_axis:=array(0..9):> > dv:=dotprod(tris2N,tris1[0]):> mm1:=TrisProjection(tris2N,tris1):> aMin:=mm1[0]: aMax:=mm1[1]:> if ((dv < aMin) or (dv > aMax)) then> plot_axis[9]:=arrow(tris1C,tris1N,shape=arrow,color=green):> else> plot_axis[9]:=arrow(tris1C,tris1N,shape=arrow,color=red):> fi:> > ct:=0:> for k from 0 to 2 do> for l from 0 to 2 do> dir:=crossprod(tris1Edg[l],tris2Edg[k]):> mm1:=TrisProjection(dir,tris1):> mm2:=TrisProjection(dir,tris2):> aMin:=mm1[0]: aMax:=mm1[1]: bMin:=mm2[0]: bMax:=mm2[1]:> if((aMax < bMin) or (bMax < aMin)) then> plot_axis[ct]:=arrow(tris1C,dir,shape=arrow,color=green):> else> plot_axis[ct]:=arrow(tris1C,dir,shape=arrow,color=red):> fi:> ct:=ct+1:> od:> od:> > plot_tris1:=polygonplot3d(tris1,axes=boxed):> plot_tris2:=polygonplot3d(tris2,axes=boxed):> ListObjectSimul:=[plot_axis[0],plot_axis[1],plot_axis[2],plot_axis[3],>   plot_axis[4],plot_axis[5],plot_axis[6],plot_axis[7],> plot_axis[8],plot_axis[9],plot_tris1,plot_tris2,>plot_axisFirst]:> > else> plot_axis1:=array(0..2):> for i from 0 to 2 do > dir:=normalize(crossprod(tris1N,tris1Edg)):> mm1:=TrisProjection(dir,tris1):> mm2:=TrisProjection(dir,tris2):> aMin:=mm1[0]: aMax:=mm1[1]: bMin:=mm2[0]: bMax:=mm2[1]:> if( (aMax < bMin) or (bMax < aMin) ) then> plot_axis1:=arrow(tris1C,dir,shape=double_arrow,color=green):> else> plot_axis1:=arrow(tris1C,dir,shape=double_arrow,color=red):> fi:> od:> > plot_axis2:=array(0..2):> for i from 0 to 2 do > dir:=normalize(crossprod(tris2N,tris2Edg)):> mm1:=TrisProjection(dir,tris1):> mm2:=TrisProjection(dir,tris2):> aMin:=mm1[0]: aMax:=mm1[1]: bMin:=mm2[0]: bMax:=mm2[1]:> if( (aMax < bMin) or (bMax < aMin) ) then> plot_axis2:=arrow(tris2C,dir,shape=double_arrow,color=blue):> else> plot_axis2:=arrow(tris2C,dir,shape=double_arrow,color=red):> fi:> od:> > plot_tris1:=polygonplot3d(tris1,axes=boxed):> plot_tris2:=polygonplot3d(tris2,axes=boxed):> ListObjectSimul:=[plot_axis1[0],plot_axis1[1],plot_axis1[2],>    plot_axis2[0],plot_axis2[1],plot_axis2[2],>   plot_tris1,plot_tris2,plot_axisFirst]:> fi:> > frame[iframe]:=ListObjectSimul:> od:> > for i from 0 to 19 do> display3d(frame,axes=boxed,labels=[x,y,z]);> od;    </pre>    </i>   <SPAN CLASS=editedby>[edited by - skarface &#111;n February 19, 2004 1:59:08 PM]</SPAN><SPAN CLASS=editedby>[edited by - skarface &#111;n February 19, 2004 2:29:31 PM]</SPAN><SPAN CLASS=editedby>[edited by - skarface &#111;n February 19, 2004 10:40:04 PM]</SPAN>   