23 const auto ab = ( b - a ).lengthSq();
24 const auto ca = ( a - c ).lengthSq();
25 const auto bc = ( c - b ).lengthSq();
32 const auto f = cross( b - a, c - a ).lengthSq();
34 return std::numeric_limits<T>::infinity();
35 return ab * ca * bc / f;
50 const auto xabSq = cross( a, b ).
lengthSq();
60 const auto ab = dot( a, b );
61 return ( bb * ( aa - ab ) * a + aa * ( bb - ab ) * b ) / ( 2 * xabSq );
78 const auto rr = sqr( radius );
83 const auto x = std::sqrt( rr - circRadSq );
84 const auto xn = x *
normal( a, b, c );
86 centerPos = circCenter + xn;
87 centerNeg = circCenter - xn;
97 const auto ab = ( b - a ).
length();
98 const auto ca = ( a - c ).
length();
99 const auto bc = ( c - b ).
length();
100 if ( ab <= 0 || ca <= 0 || bc <= 0 )
102 const auto f = cross( b - a, c - a ).length();
103 return f * std::min( { ab, ca, bc } ) / ( ab * ca * bc );
117 const auto bc = ( c - b ).
length();
118 const auto ca = ( a - c ).
length();
119 const auto ab = ( b - a ).
length();
120 auto halfPerimeter = ( bc + ca + ab ) / 2;
121 auto den = 8 * ( halfPerimeter - bc ) * ( halfPerimeter - ca ) * ( halfPerimeter - ab );
123 return std::numeric_limits<T>::max();
125 return bc * ca * ab / den;
132 return cross( t[1] - t[0], t[2] - t[0] );
139 return cross( q, r );
146 return cross( q - p, r - p );
160 return normal( q - p, r - p );
167 return normal( t[1] - t[0], t[2] - t[0] );
179[[nodiscard]]
inline T
dblArea(
const Triangle3<T> & t )
202 return std::abs( cross( q - p, r - p ) );
216 const auto c = ( t[0] + t[1] + t[2] ) / T(3);
219 for (
int i = 0; i < 3; ++i )
221 const auto sq = ( t[i] - c ).lengthSq();
222 if ( longestSq >= sq )
227 const auto d = ( t[longest] - c ).normalized();
231 for (
int i = 0; i < 3; ++i )
232 res[i] = c + d * dot( d, t[i] - c );
241 const auto c = ( t[0] + t[1] + t[2] ) / T(3);
243 for (
int i = 0; i < 3; ++i )
244 res[i] = t[i] - n * dot( n, t[i] - c );
260 return dot( edgeDir, cross( leftNorm, rightNorm ) );
271 return dot( leftNorm, rightNorm );
285 return std::atan2( sin, cos );
301 const auto aa = sqr( a );
302 const auto y = ( aa - sqr( b ) + sqr( c ) ) / ( 2 * c );
303 const auto yy = sqr( y );
306 const auto x = std::sqrt( aa - yy );
324 auto y = ( p->x * p1->y - p1->x * p->y ) / ( p->x - p1->x );
325 if ( y < 0 || y > c )
327 return ( *p - *p1 ).length();
336 const T den = ( a + b + c ) * ( b + c - a );
338 return std::numeric_limits<T>::infinity();
339 const T num = ( a + c - b ) * ( a + b - c );
348[[nodiscard]]
inline T
cotan(
const Triangle3<T> & t, T absMaxVal = std::numeric_limits<T>::max() )
350 auto a = t[0] - t[2];
351 auto b = t[1] - t[2];
352 auto nom = dot( a, b );
353 auto den = cross( a, b ).length();
354 if ( fabs( nom ) >= absMaxVal * den )
355 return absMaxVal * sgn( nom );
363[[nodiscard]]
inline T
cotan( T a, T b, T c )
365 const T den = ( a + b + c ) * ( b + c - a );
367 return -std::numeric_limits<T>::infinity();
368 const T num = ( a + c - b ) * ( a + b - c );
370 return std::numeric_limits<T>::infinity();
371 const auto tanSq = num / den;
372 return ( 1 - tanSq ) / ( 2 * std::sqrt( tanSq ) );
380 const auto bb = dot( b, b );
381 const auto bc = dot( b, c );
382 const auto cc = dot( c, c );
383 const auto det = bb * cc - bc * bc;
386 const auto kb = ( 1 / det ) * ( cc * vb - bc * vc );
387 const auto kc = ( 1 / det ) * (-bc * vb + bb * vc );
388 return kb * b + kc * c;
404 const auto gradSq = grad.
lengthSq();
407 const auto d = c - b;
409 const auto gort = d - ( dot( d, grad ) / gradSq ) * grad;
410 const auto god = dot( gort, d );
413 const auto gob = -dot( gort, b );
414 if ( gob <= 0 || gob >= god )
416 const auto a = gob / god;
417 assert( a < std::numeric_limits<T>::max() );
418 const auto ip = a * c + ( 1 - a ) * b;
419 if ( dot( grad, ip ) >= 0 )
434 if ( !grad.has_value() )
436 auto gradSq = grad->lengthSq();
439 return sqrt( 1 - gradSq ) *
normal( b, c ) - *grad;
452 return Plane3<T>( *n, dot( *n, a ) + ra );
float area(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns the area of given face
Definition MRMeshMath.h:168
MRMESH_API float circumcircleDiameter(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns circumcircle diameter of given mesh triangle
MRMESH_API float dihedralAngle(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
Vector3< T > circumcircleCenter(const Vector3< T > &a, const Vector3< T > &b)
Computes the center of the the triangle's 0AB circumcircle.
Definition MRTriMath.h:48
MRMESH_API float dihedralAngleCos(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
std::optional< T > findTriExitPos(const Vector3< T > &b, const Vector3< T > &c, const Vector3< T > &grad)
Definition MRTriMath.h:402
std::optional< T > quadrangleOtherDiagonal(T a, T b, T c, T a1, T b1)
Definition MRTriMath.h:314
Triangle3< T > makeDegenerate(const Triangle3< T > &t)
make degenerate triangle (all 3 points on a line) that maximally resembles the input one and has the ...
Definition MRTriMath.h:214
T tanSqOfHalfAngle(T a, T b, T c)
Definition MRTriMath.h:334
Triangle3< T > triangleWithNormal(const Triangle3< T > &t, const Vector3< T > &n)
Definition MRTriMath.h:239
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_API float triangleAspectRatio(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns aspect ratio of given mesh triangle equal to the ratio of the circum-radius to twice its in-r...
std::optional< Vector3< T > > gradientInTri(const Vector3< T > &b, const Vector3< T > &c, T vb, T vc)
Definition MRTriMath.h:378
std::optional< Plane3< T > > tangentPlaneToSpheres(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c, T ra, T rb, T rc)
Definition MRTriMath.h:449
MRMESH_API float circumcircleDiameterSq(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns squared circumcircle diameter of given mesh triangle
bool circumballCenters(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c, T radius, Vector3< T > ¢erPos, Vector3< T > ¢erNeg)
ball's center from the negative side of triangle
Definition MRTriMath.h:74
std::optional< Vector3< T > > tangentPlaneNormalToSpheres(const Vector3< T > &b, const Vector3< T > &c, T rb, T rc)
Definition MRTriMath.h:431
Vector3 normalized() const MR_REQUIRES_IF_SUPPORTED(std
Definition MRVector3.h:77
float dblArea(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns twice the area of given face
Definition MRMeshMath.h:162
T minTriangleAngle(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
Definition MRTriMath.h:107
std::optional< Vector2< T > > posFromTriEdgeLengths(T a, T b, T c)
Definition MRTriMath.h:292
float cotan(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId ue)
Definition MRMeshMath.h:315
T lengthSq() const
Definition MRVector3.h:68
T dblAreaSq(const Vector3< T > &p, const Vector3< T > &q, const Vector3< T > &r)
computes the square of double area of given triangle
Definition MRTriMath.h:172
length
Definition MRObjectDimensionsEnum.h:17
MRMESH_API float dihedralAngleSin(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
T minTriangleAngleSin(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
Definition MRTriMath.h:95
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRVector2.h:29
Definition MRVector3.h:33