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;
235 const T& Sx = prec.
Sx;
236 const T& Sy = prec.
Sy;
237 const T& Sz = prec.
Sz;
247 const T eps = std::numeric_limits<T>::epsilon() * std::max( { Ax, Bx, Cx, Ay, By, Cy } );
248 T U = Cx * By - Cy * Bx;
249 T V = Ax * Cy - Ay * Cx;
250 T W = Bx * Ay - By * Ax;
252 if( U < -eps || V < -eps || W < -eps )
254 if( U > eps || V > eps || W > eps )
267 const T t = U * Az + V * Bz + W * Cz;
269 auto invDet = T( 1 ) / det;
270 return TriIntersectResult(
float( V * invDet ),
float( W * invDet ),
float( t * invDet ) );
273MR_BIND_TEMPLATE( std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3<float >& oriA,
const Vector3<float >& oriB,
const Vector3<float >& oriC,
const IntersectionPrecomputes<float >& prec ) )
274MR_BIND_TEMPLATE( std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3<double>& oriA,
const Vector3<double>& oriB,
const Vector3<double>& oriC,
const IntersectionPrecomputes<double>& prec ) )
284MR_BIND_TEMPLATE( std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3<float >& oriA,
const Vector3<float >& oriB,
const Vector3<float >& oriC,
const Vector3<float >& dir ) )
285MR_BIND_TEMPLATE( std::optional<TriIntersectResult>
rayTriangleIntersect(
const Vector3<double>& oriA,
const Vector3<double>& oriB,
const Vector3<double>& oriC,
const Vector3<double>& 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
std::optional< Vector3< T > > findTriangleTriangleIntersection(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:211
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
std::optional< TriIntersectResult > rayTriangleIntersect(const Vector3< T > &oriA, const Vector3< T > &oriB, const Vector3< T > &oriC, const IntersectionPrecomputes< T > &prec)
Definition MRTriangleIntersection.h:232
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
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
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
Definition MRCameraOrientationPlugin.h:8
MRMESH_API TriangleSegmentIntersectResult doTriangleSegmentIntersect(const std::array< PreciseVertCoords, 5 > &vs)
Definition MRMeshFwd.h:503
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:30