Skip to content

Commit 73c7333

Browse files
committed
add comments
1 parent c256ed4 commit 73c7333

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/geometry_primitives.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,17 @@ orthogonal_vector(::Type{VT}, vertices) where {VT <: VecTypes{3}} = _orthogonal_
152152
orthogonal_vector(::Type{VT}, vertices::Tuple) where {VT <: VecTypes{3}} = _orthogonal_vector(VT, vertices)
153153

154154
function _orthogonal_vector(::Type{VT}, vertices) where {VT <: VecTypes{3}}
155+
# Using shoelace approach (with N+1 = 1) (see #245)
156+
# \sum_i p_i × p_{i+1}
157+
# with distance vectors to avoid float precision issues
158+
# \sum_i (p_i - p_1) × (p_{i+1} - p_1)
159+
# These terms are equal when expanded (extra terms cancel over full sum)
155160
c = zero(VT)
156161
p0 = first(vertices)
157162
prev = zero(VT)
158163
for i in eachindex(vertices)
164+
# i = 1 and N don't contribute as then produce (q_1 - q_1) terms
165+
# we need i = 1 to set up prev though
159166
i == lastindex(vertices) && break
160167
v = to_ndim(VT, vertices[i+1] - p0, 0)
161168
c += cross(prev, v)

0 commit comments

Comments
 (0)