37 const auto abcd = mixed( a - d, b - d, c - d );
38 const auto abce = mixed( a - e, b - e, c - e );
39 const auto abcf = mixed( a - f, b - f, c - f );
40 const auto abc_de = abcd * abce >= 0;
41 const auto abc_fd = abcf * abcd >= 0;
43 if ( abc_de && abc_fd && abce * abcf >= 0 )
46 const auto defa = mixed( d - a, e - a, f - a );
47 const auto defb = mixed( d - b, e - b, f - b );
48 const auto defc = mixed( d - c, e - c, f - c );
49 const auto def_ab = defa * defb >= 0;
50 const auto def_ca = defc * defa >= 0;
52 if ( def_ab && def_ca && defb * defc >= 0 )
67 const auto abde = mixed( a - e, b - e, d - e );
68 const auto abdf = mixed( a - f, b - f, d - f );
70 if ( abde * abdf < 0 )
73 const auto acde = mixed( a - e, c - e, d - e );
75 if ( abde * acde < 0 )
78 if ( abdf == 0 && acde == 0 )
81 const auto acdf = mixed( a - f, c - f, d - f );
83 if ( acde * acdf < 0 )
86 if ( abdf * acdf < 0 )
89 if ( abde == 0 && acdf == 0 )
103 const auto xy = ( y - x ).normalized();
104 d = ( d - xy * dot( xy, d ) ).normalized();
106 const auto dz = dot( d, z - x );
108 dz * dot( d, u - x ) < 0 &&
109 dz * dot( d, v - x ) < 0 &&
110 dz * dot( d, w - x ) < 0;
125 const auto dir = a + b + c - d - e - f;
143 const auto dabe = mixed( d - e, a - e, b - e );
144 const auto dbce = mixed( d - e, b - e, c - e );
145 if ( dabe * dbce <= 0 )
148 const auto dcae = mixed( d - e, c - e, a - e );
149 if ( dbce * dcae <= 0 )
152 if ( dcae * dabe <= 0 )
165 const auto abcd = mixed( a - d, b - d, c - d );
166 const auto abce = mixed( a - e, b - e, c - e );
167 if ( abcd * abce >= 0 )
179 const auto abcd = std::abs( mixed( a - d, b - d, c - d ) );
180 const auto abce = std::abs( mixed( a - e, b - e, c - e ) );
181 auto r = std::clamp( abcd / ( abcd + abce ), T( 0 ), T( 1 ) );
182 return r * e + ( 1 - r ) * d;
189 const T& Sx = prec.
Sx;
190 const T& Sy = prec.
Sy;
191 const T& Sz = prec.
Sz;
201 const T eps = std::numeric_limits<T>::epsilon() * std::max( { Ax, Bx, Cx, Ay, By, Cy } );
202 T U = Cx * By - Cy * Bx;
203 T V = Ax * Cy - Ay * Cx;
204 T W = Bx * Ay - By * Ax;
206 if( U < -eps || V < -eps || W < -eps )
208 if( U > eps || V > eps || W > eps )
221 const T t = U * Az + V * Bz + W * Cz;
223 auto invDet = T( 1 ) / det;
224 return TriIntersectResult(
float( V * invDet ),
float( W * invDet ),
float( t * invDet ) );
227inline std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3f& oriA,
const Vector3f& oriB,
const Vector3f& oriC,
232inline std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3f& oriA,
const Vector3f& oriB,
const Vector3f& oriC,
233 const Vector3f& dir )
239inline std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3d& oriA,
const Vector3d& oriB,
const Vector3d& oriC,
245inline std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3d& oriA,
const Vector3d& oriB,
const Vector3d& oriC,
246 const Vector3d& dir )
int idxY
Definition MRIntersectionPrecomputes.h:124
T Sx
precomputed factors
Definition MRIntersectionPrecomputes.h:130
int idxX
Definition MRIntersectionPrecomputes.h:123
T Sz
Definition MRIntersectionPrecomputes.h:130
T Sy
Definition MRIntersectionPrecomputes.h:130
int maxDimIdxZ
Definition MRIntersectionPrecomputes.h:122
bool doTrianglesIntersect(Vector3< T > a, Vector3< T > b, Vector3< T > c, Vector3< T > d, Vector3< T > e, Vector3< T > f)
Definition MRTriangleIntersection.h:32
bool doesEdgeXySeparate(const Vector3< T > &x, const Vector3< T > &y, const Vector3< T > &z, const Vector3< T > &u, const Vector3< T > &v, const Vector3< T > &w, Vector3< T > d)
returns true if a plane containing edge XY separates point Z from triangle UVW
Definition MRTriangleIntersection.h:97
std::optional< TriIntersectResult > rayTriangleIntersect(const Vector3f &oriA, const Vector3f &oriB, const Vector3f &oriC, const IntersectionPrecomputes< float > &prec)
Definition MRTriangleIntersection.h:227
std::optional< TriIntersectResult > rayTriangleIntersect_(const Vector3< T > &oriA, const Vector3< T > &oriB, const Vector3< T > &oriC, const IntersectionPrecomputes< T > &prec)
Definition MRTriangleIntersection.h:186
bool doTriangleLineIntersect(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c, const Vector3< T > &d, const Vector3< T > &e)
checks whether triangle ABC and infinite line DE intersect
Definition MRTriangleIntersection.h:138
Vector3< T > findTriangleSegmentIntersection(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c, const Vector3< T > &d, const Vector3< T > &e)
this function input should have intersection
Definition MRTriangleIntersection.h:174
bool doTrianglesIntersectExt(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c, const Vector3< T > &d, const Vector3< T > &e, const Vector3< T > &f)
Definition MRTriangleIntersection.h:116
Definition MRCameraOrientationPlugin.h:8
MRMESH_API TriangleSegmentIntersectResult doTriangleSegmentIntersect(const std::array< PreciseVertCoords, 5 > &vs)
Definition MRMesh/MRMeshFwd.h:374
Definition MRTriangleIntersection.h:18
TriIntersectResult(float U, float V, float dist)
Definition MRTriangleIntersection.h:23
float t
Definition MRTriangleIntersection.h:22
TriPointf bary
Definition MRTriangleIntersection.h:20
Definition MRMesh/MRVector3.h:19