43#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_IMPL_INTERSECT_TRIANGLE_3D_H
44#define LASS_GUARDIAN_OF_INCLUSION_PRIM_IMPL_INTERSECT_TRIANGLE_3D_H
68template <
typename Po
int,
typename Vector,
typename T>
inline
69Result intersectTriangle3D(
const Point& iVertex0,
const Vector& iEdge1,
const Vector& iEdge2,
70 const Point& iSupport,
const Vector& iDirection,
71 T& oU, T& oV, T& oT,
const T& iMinT)
73 typedef typename Vector::TNumTraits TNumTraits;
74 typedef num::Consistent<T> TConsistent;
76 const Vector pvec = cross(iDirection, iEdge2);
77 const T det = dot(pvec, iEdge1);
79 if (det == TNumTraits::zero)
86 const Vector tvec = iSupport - iVertex0;
87 const T u = dot(tvec, pvec) * invDet;
88 if (u < TNumTraits::zero || u > TNumTraits::one)
93 const Vector qvec = cross(tvec, iEdge1);
94 const T v = dot(iDirection, qvec) * invDet;
95 if (v < TNumTraits::zero || (u + v) > TNumTraits::one)
100 const TConsistent t = dot(iEdge2, qvec) * invDet;
122template <
typename Po
int>
123class IntersectTriangle3DWoop
127 using TPoint3D = Point;
128 using TVector3D =
typename Point::TVector;
129 using TValue =
typename Point::TValue;
131 IntersectTriangle3DWoop(
const TPoint3D& support,
const TVector3D& direction):
134 kz_ = direction.majorAxis();
137 if (direction[kz_] < 0)
141 shear_.z =
num::inv(direction[kz_]);
142 shear_.x = -direction[kx_] * shear_.z;
143 shear_.y = -direction[ky_] * shear_.z;
147 const TPoint3D& vertex0,
const TPoint3D& vertex1,
const TPoint3D& vertex2,
148 TValue b[3], TValue& t,
const TValue& tMin)
const
150 const TVector3D v0 = vertex0 - support_;
151 const TVector3D v1 = vertex1 - support_;
152 const TVector3D v2 = vertex2 - support_;
154 const TValue v0x = v0[kx_] + v0[kz_] * shear_.x;
155 const TValue v0y = v0[ky_] + v0[kz_] * shear_.y;
156 const TValue v1x = v1[kx_] + v1[kz_] * shear_.x;
157 const TValue v1y = v1[ky_] + v1[kz_] * shear_.y;
158 const TValue v2x = v2[kx_] + v2[kz_] * shear_.x;
159 const TValue v2y = v2[ky_] + v2[kz_] * shear_.y;
161 TValue u = v2x * v1y - v2y * v1x;
162 TValue v = v0x * v2y - v0y * v2x;
163 TValue w = v1x * v0y - v1y * v0x;
165 using TDouble =
typename num::DoublePrecision<TValue>::Type;
166 if constexpr (!std::is_same_v<TValue, TDouble>)
168 if (u == 0 || v == 0 || w == 0)
171 const TDouble v21xy =
static_cast<TDouble
>(v2x) *
static_cast<TDouble
>(v1y);
172 const TDouble v21yx =
static_cast<TDouble
>(v2y) *
static_cast<TDouble
>(v1x);
173 u =
static_cast<TValue
>(v21xy - v21yx);
175 const TDouble v02xy =
static_cast<TDouble
>(v0x) *
static_cast<TDouble
>(v2y);
176 const TDouble v02yx =
static_cast<TDouble
>(v0y) *
static_cast<TDouble
>(v2x);
177 v =
static_cast<TValue
>(v02xy - v02yx);
179 const TDouble v10xy =
static_cast<TDouble
>(v1x) *
static_cast<TDouble
>(v0y);
180 const TDouble v10yx =
static_cast<TDouble
>(v1y) *
static_cast<TDouble
>(v0x);
181 w =
static_cast<TValue
>(v10xy - v10yx);
185 if ((u < 0 || v < 0 || w < 0) && (u > 0 || v > 0 || w > 0))
190 const TValue det = u + v + w;
195 const TValue invDet =
num::inv(det);
197 const TValue v0z = v0[kz_] * shear_.z;
198 const TValue v1z = v1[kz_] * shear_.z;
199 const TValue v2z = v2[kz_] * shear_.z;
200 const TValue tt = (v0z * u + v1z * v + v2z * w) * invDet;
T inv(const T &x)
return x ^ -1
implementation details of lass::prim
set of geometrical primitives
Result
meta information on the result you have from an operation like an intersection ...
@ rNone
operation has no answer, output arguments are meaningless
@ rOne
there's exactly one answer, 1 output argument contains the answer
Library for Assembled Shared Sources.