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 )
99 return mixed( p - a, p - b, p - c ) == T( 0 );
108 const auto normDir = cross( b - a, c - a );
109 if ( dot( normDir, cross( b - a, p - a ) ) < 0 )
111 if ( dot( normDir, cross( c - b, p - b ) ) < 0 )
113 if ( dot( normDir, cross( a - c, p - c ) ) < 0 )
126 const auto xy = ( y - x ).normalized();
127 d = ( d - xy * dot( xy, d ) ).normalized();
129 const auto dz = dot( d, z - x );
131 dz * dot( d, u - x ) < 0 &&
132 dz * dot( d, v - x ) < 0 &&
133 dz * dot( d, w - x ) < 0;
148 const auto dir = a + b + c - d - e - f;
166 const auto dabe = mixed( d - e, a - e, b - e );
167 const auto dbce = mixed( d - e, b - e, c - e );
168 if ( dabe * dbce <= 0 )
171 const auto dcae = mixed( d - e, c - e, a - e );
172 if ( dbce * dcae <= 0 )
175 if ( dcae * dabe <= 0 )
188 const auto abcd = mixed( a - d, b - d, c - d );
189 const auto abce = mixed( a - e, b - e, c - e );
190 if ( abcd * abce >= 0 )
202 const auto abcd = std::abs( mixed( a - d, b - d, c - d ) );
203 const auto abce = std::abs( mixed( a - e, b - e, c - e ) );
204 auto r = std::clamp( abcd / ( abcd + abce ), T( 0 ), T( 1 ) );
205 return r * e + ( 1 - r ) * d;
212 const T& Sx = prec.
Sx;
213 const T& Sy = prec.
Sy;
214 const T& Sz = prec.
Sz;
224 const T eps = std::numeric_limits<T>::epsilon() * std::max( { Ax, Bx, Cx, Ay, By, Cy } );
225 T U = Cx * By - Cy * Bx;
226 T V = Ax * Cy - Ay * Cx;
227 T W = Bx * Ay - By * Ax;
229 if( U < -eps || V < -eps || W < -eps )
231 if( U > eps || V > eps || W > eps )
244 const T t = U * Az + V * Bz + W * Cz;
246 auto invDet = T( 1 ) / det;
247 return TriIntersectResult(
float( V * invDet ),
float( W * invDet ),
float( t * invDet ) );
250inline std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3f& oriA,
const Vector3f& oriB,
const Vector3f& oriC,
255inline std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3f& oriA,
const Vector3f& oriB,
const Vector3f& oriC,
256 const Vector3f& dir )
262inline std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3d& oriA,
const Vector3d& oriB,
const Vector3d& oriC,
268inline std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3d& oriA,
const Vector3d& oriB,
const Vector3d& oriC,
269 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 isPointInPlane(const Vector3< T > &p, const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
returns true if ABC plane contains point P
Definition MRTriangleIntersection.h:97
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:120
std::optional< TriIntersectResult > rayTriangleIntersect(const Vector3f &oriA, const Vector3f &oriB, const Vector3f &oriC, const IntersectionPrecomputes< float > &prec)
Definition MRTriangleIntersection.h:250
bool isPointInTriangle(const Vector3< T > &p, const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
returns true if ABC triangle contains point P
Definition MRTriangleIntersection.h:104
std::optional< TriIntersectResult > rayTriangleIntersect_(const Vector3< T > &oriA, const Vector3< T > &oriB, const Vector3< T > &oriC, const IntersectionPrecomputes< T > &prec)
Definition MRTriangleIntersection.h:209
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:161
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:197
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:139
MRMESH_API TriangleSegmentIntersectResult doTriangleSegmentIntersect(const std::array< PreciseVertCoords, 5 > &vs)
Definition MRMesh/MRMeshFwd.h:429
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:26