This function check whether there is separating axis between triangle and box. This function can be optimized by explicitly providing cross_product result see example: http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/code/tribox3.txt
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=rk), | intent(in) | :: | dirVec(3) | |||
real(kind=rk), | intent(in) | :: | edge(3) | |||
real(kind=rk), | intent(in) | :: | nodes(3,3) | |||
real(kind=rk), | intent(in) | :: | boxhalfwidth(3) |
function Axistest( dirVec, edge, nodes, boxhalfwidth ) result (success) !--------------------------------------------------------------------------! real(kind=rk), intent(in) :: dirVec(3) real(kind=rk), intent(in) :: edge(3) real(kind=rk), intent(in) :: nodes(3,3) real(kind=rk), intent(in) :: boxhalfwidth(3) logical :: success !--------------------------------------------------------------------------! real(kind=rk) :: vecA(3), p1, p2, p3, pmin, pmax, rad !--------------------------------------------------------------------------! success = .true. ! a_(i,j) = e_i x f_j vecA = cross_product3D( dirVec, edge ) p1 = dot_product( vecA, nodes(:,1) ) p2 = dot_product( vecA, nodes(:,2) ) p3 = dot_product( vecA, nodes(:,3) ) pmin = min(p1, p2, p3) pmax = max(p1, p2, p3) rad = abs(vecA(1)) * boxhalfwidth(1) & & + abs(vecA(2)) * boxhalfwidth(2) & & + abs(vecA(3)) * boxhalfwidth(3) if (pmin > rad .or. pmax < -rad) return success = .false. end function Axistest