20 const auto ab = ( b - a ).lengthSq();
21 const auto ca = ( a - c ).lengthSq();
22 const auto bc = ( c - b ).lengthSq();
29 const auto f = cross( b - a, c - a ).lengthSq();
31 return std::numeric_limits<T>::infinity();
32 return ab * ca * bc / f;
47 const auto xabSq = cross( a, b ).lengthSq();
57 const auto ab = dot( a, b );
58 return ( bb * ( aa - ab ) * a + aa * ( bb - ab ) * b ) / ( 2 * xabSq );
75 const auto rr =
sqr( radius );
80 const auto x = std::sqrt( rr - circRadSq );
81 const auto xn = x *
normal( a, b, c );
83 centerPos = circCenter + xn;
84 centerNeg = circCenter - xn;
94 const auto ab = ( b - a ).
length();
95 const auto ca = ( a - c ).
length();
96 const auto bc = ( c - b ).
length();
97 if ( ab <= 0 || ca <= 0 || bc <= 0 )
99 const auto f = cross( b - a, c - a ).length();
100 return f * std::min( { ab, ca, bc } ) / ( ab * ca * bc );
114 const auto bc = ( c - b ).
length();
115 const auto ca = ( a - c ).
length();
116 const auto ab = ( b - a ).
length();
117 auto halfPerimeter = ( bc + ca + ab ) / 2;
118 auto den = 8 * ( halfPerimeter - bc ) * ( halfPerimeter - ca ) * ( halfPerimeter - ab );
120 return std::numeric_limits<T>::max();
122 return bc * ca * ab / den;
129 return cross( t[1] - t[0], t[2] - t[0] );
136 return cross( q, r );
143 return cross( q - p, r - p );
157 return normal( q - p, r - p );
169[[nodiscard]]
inline T
dblArea(
const Triangle3<T> & t )
192 return std::abs( cross( q - p, r - p ) );
206 const auto c = ( t[0] + t[1] + t[2] ) / T(3);
209 for (
int i = 0; i < 3; ++i )
211 const auto sq = ( t[i] - c ).lengthSq();
212 if ( longestSq >= sq )
217 const auto d = ( t[longest] - c ).normalized();
221 for (
int i = 0; i < 3; ++i )
222 res[i] = c + d * dot( d, t[i] - c );
231 const auto c = ( t[0] + t[1] + t[2] ) / T(3);
233 for (
int i = 0; i < 3; ++i )
234 res[i] = t[i] - n * dot( n, t[i] - c );
250 return dot( edgeDir, cross( leftNorm, rightNorm ) );
261 return dot( leftNorm, rightNorm );
275 return std::atan2( sin, cos );
291 const auto aa =
sqr( a );
292 const auto y = ( aa -
sqr( b ) +
sqr( c ) ) / ( 2 * c );
293 const auto yy =
sqr( y );
296 const auto x = std::sqrt( aa - yy );
314 auto y = ( p->x * p1->y - p1->x * p->y ) / ( p->x - p1->x );
315 if ( y < 0 || y > c )
317 return ( *p - *p1 ).length();
326 const T den = ( a + b + c ) * ( b + c - a );
328 return std::numeric_limits<T>::infinity();
329 const T num = ( a + c - b ) * ( a + b - c );
338[[nodiscard]]
inline T
cotan(
const Triangle3<T> & t, T absMaxVal = std::numeric_limits<T>::max() )
340 auto a = t[0] - t[2];
341 auto b = t[1] - t[2];
342 auto nom = dot( a, b );
343 auto den = cross( a, b ).length();
344 if ( fabs( nom ) >= absMaxVal * den )
345 return absMaxVal *
sgn( nom );
353[[nodiscard]]
inline T
cotan( T a, T b, T c )
355 const T den = ( a + b + c ) * ( b + c - a );
357 return -std::numeric_limits<T>::infinity();
358 const T num = ( a + c - b ) * ( a + b - c );
360 return std::numeric_limits<T>::infinity();
361 const auto tanSq = num / den;
362 return ( 1 - tanSq ) / ( 2 * std::sqrt( tanSq ) );
370 const auto bb = dot( b, b );
371 const auto bc = dot( b, c );
372 const auto cc = dot( c, c );
373 const auto det = bb * cc - bc * bc;
376 const auto kb = ( 1 / det ) * ( cc * vb - bc * vc );
377 const auto kc = ( 1 / det ) * (-bc * vb + bb * vc );
378 return kb * b + kc * c;
394 const auto gradSq = grad.
lengthSq();
397 const auto d = c - b;
399 const auto gort = d - ( dot( d, grad ) / gradSq ) * grad;
400 const auto god = dot( gort, d );
403 const auto gob = -dot( gort, b );
404 if ( gob <= 0 || gob >= god )
406 const auto a = gob / god;
407 assert( a < std::numeric_limits<T>::max() );
408 const auto ip = a * c + ( 1 - a ) * b;
409 if ( dot( grad, ip ) >= 0 )
424 if ( !grad.has_value() )
426 auto gradSq = grad->lengthSq();
429 return sqrt( 1 - gradSq ) *
normal( b, c ) - *grad;
442 return Plane3<T>( *n, dot( *n, a ) + ra );
length
Definition MRObjectDimensionsEnum.h:14
T minTriangleAngleSin(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
Definition MRTriMath.h:92
Definition MRCameraOrientationPlugin.h:8
float area(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns the area of given face
Definition MRMeshMath.h:165
constexpr T sqr(T x) noexcept
squared value
Definition MRMesh/MRMeshFwd.h:753
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:45
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:392
std::optional< T > quadrangleOtherDiagonal(T a, T b, T c, T a1, T b1)
Definition MRTriMath.h:304
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:204
T tanSqOfHalfAngle(T a, T b, T c)
Definition MRTriMath.h:324
Triangle3< T > triangleWithNormal(const Triangle3< T > &t, const Vector3< T > &n)
Definition MRTriMath.h:229
Vector3f dirDblArea(const MeshTopology &topology, const VertCoords &points, FaceId f)
computes directed double area for a triangular face from its vertices
Definition MRMeshMath.h:150
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...
constexpr int sgn(T x) noexcept
sign of given value in { -1, 0, 1 }
Definition MRMesh/MRMeshFwd.h:757
std::optional< Vector3< T > > gradientInTri(const Vector3< T > &b, const Vector3< T > &c, T vb, T vc)
Definition MRTriMath.h:368
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:439
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)
Definition MRTriMath.h:71
std::optional< Vector3< T > > tangentPlaneNormalToSpheres(const Vector3< T > &b, const Vector3< T > &c, T rb, T rc)
Definition MRTriMath.h:421
float dblArea(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns twice the area of given face
Definition MRMeshMath.h:159
T minTriangleAngle(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
Definition MRTriMath.h:104
std::optional< Vector2< T > > posFromTriEdgeLengths(T a, T b, T c)
Definition MRTriMath.h:282
float cotan(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId ue)
Definition MRMeshMath.h:309
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:162
MRMESH_API float dihedralAngleSin(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
Definition MRVector2.h:27
Definition MRMesh/MRVector3.h:28
Vector3 normalized() const MR_REQUIRES_IF_SUPPORTED(std
Definition MRMesh/MRVector3.h:68
T lengthSq() const
Definition MRMesh/MRVector3.h:59