Skip to main content
. Author manuscript; available in PMC: 2018 Nov 1.
Published in final edited form as: J Biomed Inform. 2017 Sep 22;75:48–62. doi: 10.1016/j.jbi.2017.09.010

Algorithm 1.

Edge-edge continuous collision detection for thread self-collision

1: procedure selfCollisionDetection
2: for each line segment i = 1 → N do
3:   for each proximate line segment j (found in broad phase) do
4:    compute w(tt) from current positions
5:    compute [or retrieve] w(t) from previous positions
6:    compute |w(t)|, |w(tt)|, m = sign(w(t).w(tt))
7:    if |w(tt)| − m|w(tt)| ≤ 0 then
8:     return false; (no collision)
9:    else
10:     if si(tt) < 0 or si(tt) > 1 or si(tt) < 0 or si(tt) > 1 then
11:      (case when w(tt) lies outside any of line segment)
12:      compute (tt)
13:     else
14:      set (tt) = w(tt)
15:     end if
16:     if |(tt)| < D then
17:      return true; (collision)
18:     else
19:      if sign(w(t).w(tt) < 0 and 0 ≤ si(tt), sj(tt) ≤ 1 then
20:       return true; (collision)
21:      else
22:       return false; (no collision)
23:      end if
24:     end if
25:    end if
26:   end for
27: end for
28: end procedure