# 4.3. 线性对象与三角形的交

## 4.3. 线性对象与三角形的交

Möller&Trumbore(1997)[1]提出了一种更加高效的射线与三角形相交测试的算法，而且乘法或者除法操作造成的误差叠加较少，精度损失更小，因此性能上更加健壮。

$$T(u,v) = (1 – u – v){V_0} + u{V_1} + v{V_2} \tag{4.18}$$

$P + t\vec d = \left( {1 – u – v} \right){V_0} + u{V_1} + v{V_2} \tag{4.19}$

$\left[ {\begin{array}{*{20}{c}}{ – \vec d}&{{V_1} – {V_0}}&{{V_2} – {V_0}}\end{array}} \right]\left[ {\begin{array}{*{20}{c}}t\\u\\v\end{array}} \right] = \left[ {P – {V_0}} \right] \tag{4.20}$

$\left[ {\begin{array}{*{20}{c}}t\\u\\v\end{array}} \right] = \frac{1}{{\left| {\begin{array}{*{20}{c}}{ – \vec d}&{{E_1}}&{{E_2}}\end{array}} \right|}}\left[ {\begin{array}{*{20}{c}}{|T}&{{E_1}}&{{E_2}|}\\{| – \vec d}&T&{{E_2}|}\\{| – \vec d}&{{E_1}}&{T|}\end{array}} \right] \tag{4.21}$

$\left[ {\begin{array}{*{20}{c}}t\\u\\v\end{array}} \right] = \frac{1}{{\left( {\vec d \times {E_2}} \right) \cdot {E_1}}}\left[ {\begin{array}{*{20}{c}}{\left( {T \times {E_1}} \right) \cdot {E_2}}\\{\left( {\vec d \times {E_2}} \right) \cdot T}\\{\left( {T \times {E_1}} \right) \cdot \vec d}\end{array}} \right] \tag{4.22}$

return ({OVERLAPPING, PARALLEL, DISJOINT, INTERSECTING})
1.    $$T = P – {V_0},{E_1} = {V_1} – {V_0},{E_2} = {V_2} – {V_0}$$;
2.    $$M = \vec d \times {E_2}$$;
3.    $$det = M \cdot {E_1}$$;
4.    if$$det = = 0$$，then
5.           $$d = \left( {{E_1} \times {E_2}} \right) \cdot T$$;
6.           if$$d = = 0$$, then
7.                  return OVERLAPPING;                     //直线与平面$$\pi$$重叠
8.           else
9.                  return PARALLEL;                            //直线与平面$$\pi$$平行
10.          end if
11.   else
12.          $$K = T \times {E_1}$$;
13.          $$t = K \cdot {E_2}/det$$；
14.          $$u = M \cdot T/det$$;
15.          $$v = K \cdot \vec d/det$$;
16.          if $$u \prec 0$$||$$v \prec 0$$||$$u + v \succ 1$$，then
17.                 return DISJOINT；                            //直线与三角形不相交
18.          else
19.                 $$Q = P + t\vec d$$;
20.                 return INTERSECTING;                     //直线与三角形相交于点$$Q$$
21.          end if;
22.   end if;