31 if(std::abs(segmentDir.
x()) > std::abs(segmentDir.
y()))
34 if(std::abs(segmentDir.
x()) > std::abs(segmentDir.
z()))
36 segmentDir.
set({segmentDir.
y(), segmentDir.
z(), segmentDir.
x()});
37 vAt.
set({vAt.
y(), vAt.
z(), vAt.
x()});
38 vBt.
set({vBt.
y(), vBt.
z(), vBt.
x()});
39 vCt.
set({vCt.
y(), vCt.
z(), vCt.
x()});
50 if(std::abs(segmentDir.
y()) > std::abs(segmentDir.
z()))
52 segmentDir.
set({segmentDir.
z(), segmentDir.
x(), segmentDir.
y()});
53 vAt.
set({vAt.
z(), vAt.
x(), vAt.
y()});
54 vBt.
set({vBt.
z(), vBt.
x(), vBt.
y()});
55 vCt.
set({vCt.
z(), vCt.
x(), vCt.
y()});
64 PH_ASSERT_MSG(segmentDir.
z() !=
static_cast<T
>(0) && std::isfinite(segmentDir.
z()),
65 std::to_string(segmentDir.
z()));
67 const T rcpSegmentDirZ = T(1) / segmentDir.
z();
68 const T shearX = -segmentDir.
x() * rcpSegmentDirZ;
69 const T shearY = -segmentDir.
y() * rcpSegmentDirZ;
70 const T shearZ = rcpSegmentDirZ;
72 vAt.
x() += shearX * vAt.
z();
73 vAt.
y() += shearY * vAt.
z();
74 vBt.
x() += shearX * vBt.
z();
75 vBt.
y() += shearY * vBt.
z();
76 vCt.
x() += shearX * vCt.
z();
77 vCt.
y() += shearY * vCt.
z();
79 T funcEa = vBt.
x() * vCt.
y() - vBt.
y() * vCt.
x();
80 T funcEb = vCt.
x() * vAt.
y() - vCt.
y() * vAt.
x();
81 T funcEc = vAt.
x() * vBt.
y() - vAt.
y() * vBt.
x();
85 if constexpr(
sizeof(T) <
sizeof(float64))
87 if(funcEa ==
static_cast<T
>(0) || funcEb ==
static_cast<T
>(0) || funcEc ==
static_cast<T
>(0))
89 const float64 funcEa64 =
static_cast<float64
>(vBt.
x()) *
static_cast<float64
>(vCt.
y()) -
90 static_cast<float64
>(vBt.
y()) *
static_cast<float64
>(vCt.
x());
91 const float64 funcEb64 =
static_cast<float64
>(vCt.
x()) *
static_cast<float64
>(vAt.
y()) -
92 static_cast<float64
>(vCt.
y()) *
static_cast<float64
>(vAt.
x());
93 const float64 funcEc64 =
static_cast<float64
>(vAt.
x()) *
static_cast<float64
>(vBt.
y()) -
94 static_cast<float64
>(vAt.
y()) *
static_cast<float64
>(vBt.
x());
96 funcEa =
static_cast<T
>(funcEa64);
97 funcEb =
static_cast<T
>(funcEb64);
98 funcEc =
static_cast<T
>(funcEc64);
102 if((funcEa <
static_cast<T
>(0) || funcEb < static_cast<T>(0) || funcEc < static_cast<T>(0)) &&
103 (funcEa >
static_cast<T
>(0) || funcEb >
static_cast<T
>(0) || funcEc >
static_cast<T
>(0)))
109 const T determinant = funcEa + funcEb + funcEc;
110 if(determinant ==
static_cast<T
>(0) || !std::isfinite(determinant))
119 const T hitTscaled = funcEa * vAt.
z() + funcEb * vBt.
z() + funcEc * vCt.
z();
120 if(determinant >
static_cast<T
>(0))
122 if(hitTscaled < segment.
getMinT() * determinant || hitTscaled > segment.
getMaxT() * determinant)
129 if(hitTscaled > segment.
getMinT() * determinant || hitTscaled < segment.
getMaxT() * determinant)
137 PH_ASSERT_MSG(determinant !=
static_cast<T
>(0) && std::isfinite(determinant),
138 std::to_string(determinant));
140 const T rcpDeterminant =
static_cast<T
>(1) / determinant;
141 const T baryA = funcEa * rcpDeterminant;
142 const T baryB = funcEb * rcpDeterminant;
143 const T baryC = funcEc * rcpDeterminant;
144 const T hitT = hitTscaled * rcpDeterminant;
147 *out_hitBarycentricCoords = TVector3<T>(baryA, baryB, baryC);