Far-Field Evaluation to Compute the Linking Number with a
Two-Tree Barnes–Hut
Ante Qu
June 3, 2021
This is a supplemental document for our paper, Fast Linking Numbers for Topology Verification of Loopy Structures.[2] This document should guide the reader in implementing the two-tree Barnes–Hut far-field evaluation for accumulating the linking number integral between two polylines.
1
Set up and notation
Here is the Barnes–Hut far-field expansion from our paper [2], expanded about (˜r1, ˜r2):
λ = − Z ds dt (r01× r02) · ∇G(r1, r2). (1) λ = − Z ds dt (r01× r02) · ∇G(˜r1, ˜r2) + ((r01× r02) ⊗ (−(r1− ˜r1) + (r2− ˜r2))) · ∇2G(˜r1, ˜r2) +1 2((r 0 1× r 0 2) ⊗ (−(r1− ˜r1) + (r2− ˜r2)) ⊗ (−(r1− ˜r1) + (r2− ˜r2))) · ∇3G(˜r1, ˜r2) + O(|˜r1− ˜r2|−5) . (2)
Here the subscripts 1 and 2 refer to the two different curves, and ds and dt parameterize the curves, respectively, for the double line integral. That is, r1= r1(s), r2= r2(t), r01= dr1/ds, and r02= dr2/dt. We
use Cartesian coordinates in this derivation and in our implementation.
Here are some helpful definitions. The ⊗ symbol denotes an outer product, and the dot product (·) denotes an inner product over all dimensions in order, e.g., if A and B are 2-tensors, then
A · B = 3 X i=1 3 X j=1 AijBij.
Furthermore, any two tensors written adjacent to each other indicates contracting the last index of the left tensor with the first index of the right tensor (e.g. matrix multiplication); for example, if A is a 2-tensor and B is a 3-tensor, then AB can be defined by
(AB)ijk= 3
X
l=1
AilBljk.
Copyright© 2021 Ante Qu. This is an open-access article distributed under the terms of the Creative Commons Attribution 3.0 Unported License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.
2
Derivatives of G(˜
r
1, ˜
r
2)
Here are the derivatives of G(˜r1, ˜r2). Let ˜r = ˜r2− ˜r1. Then
∇G(˜r1, ˜r2) = ˜r 4π|˜r|3; (3) ∇2G(˜r 1, ˜r2) = I3×3|˜r|2− 3˜r ⊗ ˜r 4π|˜r|5 ; (4) ∇3G(˜r1, ˜r2) = −3P3 i=1(˜r ⊗ ei⊗ ei+ ei⊗ ˜r ⊗ ei+ ei⊗ ei⊗ ˜r) 4π|˜r|5 + 15˜r ⊗ ˜r ⊗ ˜r 4π|˜r|7 , (5)
where ei is the i-th basis element. Note that these are identical to the basis functions in Appendix A of [1],
except the third derivative there (Eq. 24 in [1]) has a misprint.
These expressions can be expanded and rearranged so that for each term, the s and t integrals can be separated; this allows us to use the multipole moments directly.
3
Computing the Multipole Moment Tree
Let’s discuss how to build the moment tree. Here are the moments:
cM = Z r0ds; (6) CD= Z r0(r − ˜r)T ds; (7) CQ= Z r0⊗ (r − ˜r) ⊗ (r − ˜r) ds. (8) For a line-segment element, we set ˜r to the midpoint, and, evaluating the integrals over a line segment, we get that cM is the displacement between the endpoints, CD= 0, and CQ= 121cM ⊗ cM ⊗ cM.
When we combine bounding boxes into their parents, we need to sum and shift moments. We append the subscript p or c to cM, CD, CQ to denote whether it’s the moment for the parent or child node, respectively.
Let rc be the displacement ˜rc− ˜rp (from the parent node, indexed by p, to the child node, c), and simply
use cM p= X c cM c; (9) CDp= X c CDc+ cM crTc; (10) CQpijk= X c
CQcijk+ CDcijrck+ CDcikrcj+ cM circjrck, (11)
to compute the parent moments (cM p, CDp, and CQp).
4
Evaluating a Far-Field Expansion Using Moments Between Two
Nodes at ˜
r
1and ˜
r
2We can now rewrite the Barnes–Hut far-field expansion (Eq. (2)) using the moments we just built. The final results in§4.4 are what we use in our implementation.
Append the subscript 1 or 2 to cM, CD, CQ to denote whether it’s the moment for the node at ˜r1 or
˜r2, respectively. Furthermore, let p1 = r1− ˜r1, p2 = r2− ˜r2. We will look at the different orders of the
Barnes–Hut far-field expansion separately: the monopole term tM (which contains ∇G), the dipole term tD
(which contains ∇2G), and the quadrupole term t
Q (which contains ∇3G). The dipole implementation on
the GPU uses ˜λ = tM + tD, and the quadrupole implementation on the CPU uses ˜λ = tM + tD+ tQ, to
4.1
Monopole:
Let’s call the monopole term (which contains ∇G in the integrand) tM.
tM = − Z ds dt (r01× r02) · ∇G, = −1 4π|˜r|3 Z ds r01 × Z dt r02 · ˜r, = −1 4π|˜r|3˜r · (cM 1× cM 2). (12)
4.2
Dipole:
Let’s call the dipole terms (which contain ∇2G in the integrand) tD.
tD= −
Z
ds dt ((r01× r02) ⊗ (−p1+ p2)) · ∇2G; (13)
4π|˜r|5∇2G = |˜r|2I
3×3− 3˜r ⊗ ˜r. (14)
Let tDa be the contribution from the first term in the RHS of (14), and tDb be the contribution from the
second term. Then tD= tDa+ tDb.
tDa= −1 4π|˜r|3 Z ds dt ((r01× r02) ⊗ (−p1+ p2)) · I3×3, = −1 4π|˜r|3 Z ds dt ((r01× r02) · (−p1+ p2)), = −1 4π|˜r|3 Z ds (r01× p1) · Z dt r02 + Z dt (r02× p2) · Z ds r01 , = −1
4π|˜r|3ijk(CD1ijcM 2k+ CD2ijcM 1k), (15)
where ijk is the Levi-Cevita symbol, and terms with repeated indices ({i, j, k, l, m}) are summed across the
three dimensions (1, 2, 3) for each index (Einstein notation).
tDb= +3 4π|˜r|5 Z ds dt ((r01× r02) ⊗ (−p1+ p2)) · (˜r ⊗ ˜r), = +3 4π|˜r|5 Z ds dt (((r01× r02) · ˜r)((−p1+ p2) · ˜r)), = −3 4π|˜r|5 Z ds dt ((˜r · p1)(r01· (r02× ˜r)) + (˜r · p2)(r02· (r01× ˜r))), = −3 4π|˜r|5 ˜rT Z ds p1r0T1 Z dt r02 × ˜r + ˜rT Z dt p2r0T2 Z ds r01 × ˜r , = −3 4π|˜r|5((CD1˜r) · (cM 2× ˜r) + (CD2˜r) · (cM 1× ˜r)). (16) Therefore tD= −1 4π|˜r|5(|˜r| 2
ijk(CD1ijcM 2k+ CD2ijcM 1k) + 3((CD1˜r) · (cM 2× ˜r) + (CD2˜r) · (cM 1× ˜r))). (17)
4.3
Quadrupole:
Let’s call the quadrupole terms (which contain ∇3G in the integrand) t
Q, and index any subterms by tQa,
Let’s first expand the (−p1+ p2) ⊗ (−p1+ p2) in tQ: tQ= − 1 2 Z ds dt ((r01× r02) ⊗ (−p1+ p2) ⊗ (−p1+ p2)) · ∇3G. (18) tQa= − 1 2 Z ds dt ((r01× r02) ⊗ p1⊗ p1) · ∇3G, (19) tQb= 1 2 Z ds dt ((r01× r02) ⊗ p1⊗ p2) · ∇3G, (20) tQc= 1 2 Z ds dt ((r01× r0 2) ⊗ p2⊗ p1) · ∇3G, and (21) tQd= − 1 2 Z ds dt ((r01× r02) ⊗ p2⊗ p2) · ∇3G. (22) In Einstein notation, (∇3G)ijk = 3 4π|˜r|7(5˜ri˜rj˜rk− |˜r| 2(˜r iδjk+ ˜rjδik+ ˜rkδij)). (23)
where δij is the identity matrix I3×3.
Let’s simplify tQa. Also note that CQ is symmetric in its last two dimensions.
tQa= − 1 2 Z ds dt ((r01× r02) ⊗ p1⊗ p1) · ∇3G, = 1 2 Z dt [r02]× Z ds r01⊗ p1⊗ p1 · ∇3G, = 1 2ijkcM 2iCQ1jlm(∇ 3G) klm, = 3ijk 8π|˜r|7 5cM 2iCQ1jlmr˜k˜rlr˜m− |˜r| 2(c M 2iCQ1jllr˜k+ 2cM 2iCQ1jkl˜rl) . (24)
Similarly, let’s simplify tQb:
tQb= 1 2 Z ds dt ((r01× r02) ⊗ p1⊗ p2) · ∇3G, = 1 2ijkCD1ilCD2jm(∇ 3G) klm, = 3ijk 8π|˜r|7 5CD1ilCD2jmr˜kr˜lr˜m+ |˜r| 2(C
D1ijCD2kl˜rl− CD1ilCD2jkr˜l− CD1ilCD2jl˜rk) . (25)
Because ∇3G is symmetric in its last two dimensions, t
Qc= tQb. By symmetry to tQa, tQd= −3ijk 8π|˜r|7 5cM 1iCQ2jlmr˜kr˜l˜rm− |˜r| 2 (cM 1iCQ2jll˜rk+ 2cM 1iCQ2jklr˜l) . (26)
Summing and sanitizing each term by rearranging indices alphabetically,
tQ=
3ijk
8π|˜r|7(5˜ri˜rlr˜m(cM 2jCQ1klm− cM 1jCQ2klm+ 2CD1jlCD2km)
+ |˜r|2r˜i(cM 1jCQ2kll− cM 2jCQ1kll− 2CD1jlCD2kl)
4.4
The Three Terms:
Putting them together:
tM = −1 4π|˜r|3˜r · (cM 1× cM 2); (28) tD= −1 4π|˜r|5(|˜r| 2
ijk(CD1ijcM 2k+ CD2ijcM 1k) + 3((CD1˜r) · (cM 2× ˜r) + (CD2˜r) · (cM 1× ˜r))); (29)
tQ =
3ijk
8π|˜r|7(5˜rir˜lr˜m(cM 2jCQ1klm− cM 1jCQ2klm+ 2CD1jlCD2km)
+ |˜r|2r˜i(cM 1jCQ2kll− cM 2jCQ1kll− 2CD1jlCD2kl)
+ 2|˜r|2˜rl(cM 1iCQ2jkl− cM 2iCQ1jkl+ CD1ijCD2kl− CD1ilCD2jk) . (30)
As stated earlier, we use the dipole approximation, ˜λ = tM + tD, on the GPU, and the quadrupole
approximation, ˜λ = tM + tD+ tQ, on the CPU, to compute the contribution to the Gauss linking integral
from a pair of nodes.
References
[1] Gavin Barill, Neil G. Dickson, Ryan Schmidt, David I. W. Levin, and Alec Jacobson. Fast winding numbers for soups and clouds. ACM Transactions on Graphics (TOG), 37(4):43:1–43:12, August 2018. [2] Ante Qu and Doug L. James. Fast linking numbers for topology verification of loopy structures. ACM