39 if ( ab2 >= bc2 && ab2 >= ca2 )
81 const auto abcd =
mixed( a - d, b - d, c - d );
82 const auto abce =
mixed( a - e, b - e, c - e );
83 const auto abcf =
mixed( a - f, b - f, c - f );
84 const auto abc_de = abcd * abce >= 0;
85 const auto abc_fd = abcf * abcd >= 0;
87 if ( abc_de && abc_fd && abce * abcf >= 0 )
90 const auto defa =
mixed( d - a, e - a, f - a );
91 const auto defb =
mixed( d - b, e - b, f - b );
92 const auto defc =
mixed( d - c, e - c, f - c );
93 const auto def_ab = defa * defb >= 0;
94 const auto def_ca = defc * defa >= 0;
96 if ( def_ab && def_ca && defb * defc >= 0 )
111 const auto abde =
mixed( a - e, b - e, d - e );
112 const auto abdf =
mixed( a - f, b - f, d - f );
114 if ( abde * abdf < 0 )
117 const auto acde =
mixed( a - e, c - e, d - e );
119 if ( abde * acde < 0 )
122 if ( abdf == 0 && acde == 0 )
125 const auto acdf =
mixed( a - f, c - f, d - f );
127 if ( acde * acdf < 0 )
130 if ( abdf * acdf < 0 )
133 if ( abde == 0 && acdf == 0 )
143 return mixed( p - a, p - b, p - c ) == T( 0 );
153 return cross( p - a, p - b ).lengthSq() == T( 0 );
160 return cross( p - a, p - b ) == T( 0 );
170 return dot( p - a, b - a ) >= 0 &&
dot( p - b, a - b ) >= 0;
180 return dot( p - a, b - a ) >= 0 &&
dot( p - b, a - b ) >= 0;
194 const auto normDir =
cross( b - a, c - a );
195 if (
dot( normDir,
cross( b - a, p - a ) ) < 0 )
197 if (
dot( normDir,
cross( c - b, p - b ) ) < 0 )
199 if (
dot( normDir,
cross( a - c, p - c ) ) < 0 )
201 if ( normDir.lengthSq() == 0 )
205 if ( a == b && b == c && p != a )
207 if (
dot( b - a, c - a ) <= 0 )
209 else if ( ( b - a ).lengthSq() > ( c - a ).lengthSq() )
221 const auto normSign =
cross( b - a, c - a );
222 if ( normSign *
cross( b - a, p - a ) < 0 )
224 if ( normSign *
cross( c - b, p - b ) < 0 )
226 if ( normSign *
cross( a - c, p - c ) < 0 )
231 if ( a == b && b == c && p != a )
233 if (
dot( b - a, c - a ) <= 0 )
235 else if ( ( b - a ).lengthSq() > ( c - a ).lengthSq() )
257 const auto xy = ( y - x ).normalized();
258 d = ( d - xy *
dot( xy, d ) ).normalized();
260 const auto dz =
dot( d, z - x );
262 dz *
dot( d, u - x ) < 0 &&
263 dz *
dot( d, v - x ) < 0 &&
264 dz *
dot( d, w - x ) < 0;
281 const auto dir = a + b + c - d - e - f;
299 const auto dabe =
mixed( d - e, a - e, b - e );
300 const auto dbce =
mixed( d - e, b - e, c - e );
301 if ( dabe * dbce <= 0 )
304 const auto dcae =
mixed( d - e, c - e, a - e );
305 if ( dbce * dcae <= 0 )
308 if ( dcae * dabe <= 0 )
321 const auto abcd =
mixed( a - d, b - d, c - d );
322 const auto abce =
mixed( a - e, b - e, c - e );
323 if ( abcd * abce >= 0 )
335 const auto abcd = std::abs(
mixed( a - d, b - d, c - d ) );
336 const auto abce = std::abs(
mixed( a - e, b - e, c - e ) );
337 auto r = std::clamp( abcd / ( abcd + abce ), T( 0 ), T( 1 ) );
338 return r * e + ( 1 - r ) * d;
368 const T& Sx = prec.
Sx;
369 const T& Sy = prec.
Sy;
370 const T& Sz = prec.
Sz;
380 const T eps = std::numeric_limits<T>::epsilon() * std::max( { Ax, Bx, Cx, Ay, By, Cy } );
381 T U = Cx * By - Cy * Bx;
382 T V = Ax * Cy - Ay * Cx;
383 T W = Bx * Ay - By * Ax;
385 if( U < -eps || V < -eps || W < -eps )
387 if( U > eps || V > eps || W > eps )
400 const T t = U * Az + V * Bz + W * Cz;
402 auto invDet = T( 1 ) / det;
403 return TriIntersectResult(
float( V * invDet ),
float( W * invDet ),
float( t * invDet ) );
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
TriPointf
Definition MRMeshFwd.h:497
auto dot(const Matrix2< T > &a, const Matrix2< T > &b) -> decltype(dot(a.x, b.x))
double-dot product: x = a : b
Definition MRMatrix2.h:142
TriangleSegmentIntersectResult doTriangleSegmentIntersect(const std::array< PreciseVertCoords, 5 > &vs)
Vector3f dirDblArea(const MeshTopology &topology, const VertCoords &points, FaceId f)
computes directed double area for a triangular face from its vertices
Definition MRMeshMath.h:153
MRMESH_CLASS Vector2
Definition MRMeshFwd.h:204
T mixed(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
mixed product
Definition MRVector3.h:208
bool doSegmentsIntersect(const LineSegm< V > &x, const LineSegm< V > &y, typename V::ValueType *xPos=nullptr, typename V::ValueType *yPos=nullptr)
Definition MRLineSegm.h:56
MRMESH_CLASS Vector3
Definition MRMeshFwd.h:218
std::optional< T > distanceSq(const Plane3< T > &plane1, const Plane3< T > &plane2, T errorLimit=std::numeric_limits< T >::epsilon() *T(20))
Definition MRIntersection.h:90
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:344
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:141
void rotateToLongestEdge(Vector3< T > &a, Vector3< T > &b, Vector3< T > &c)
Definition MRTriangleIntersection.h:34
bool doTrianglesIntersect(Vector3< T > a, Vector3< T > b, Vector3< T > c, Vector3< T > d, Vector3< T > e, Vector3< T > f)
Definition MRTriangleIntersection.h:65
std::optional< TriIntersectResult > rayTriangleIntersect(const Vector3< T > &oriA, const Vector3< T > &oriB, const Vector3< T > &oriC, const IntersectionPrecomputes< T > &prec)
Definition MRTriangleIntersection.h:365
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:251
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:190
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:294
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:330
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:272
bool doTrianglesOverlap(const Vector2< T > &a, const Vector2< T > &b, const Vector2< T > &c, const Vector2< T > &d, const Vector2< T > &e, const Vector2< T > &f)
returns true if ABC and DEF overlaps or touches
Definition MRTriangleIntersection.h:422
bool isPointInLine(const Vector3< T > &p, const Vector3< T > &a, const Vector3< T > &b)
returns true if AB line contains point P
Definition MRTriangleIntersection.h:151
bool isPointInSegm(const Vector3< T > &p, const Vector3< T > &a, const Vector3< T > &b)
returns true if AB segment contains point P
Definition MRTriangleIntersection.h:165
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRIntersectionPrecomputes.h:117
a segment of straight dimensional line
Definition MRLineSegm.h:15
Definition MRTriangleIntersection.h:20
TriIntersectResult(float U, float V, float dist)
Definition MRTriangleIntersection.h:25
float t
distance from ray origin to p in dir length units
Definition MRTriangleIntersection.h:24
TriPointf bary
barycentric representation
Definition MRTriangleIntersection.h:22
Definition MRVector2.h:29
T cross(const Vector2< T > &a, const Vector2< T > &b)
cross product
Definition MRVector2.h:160
Definition MRVector3.h:33