6#include "MRPch/MRBindingMacros.h"
24 const auto ab = ( b - a ).lengthSq();
25 const auto ca = ( a - c ).lengthSq();
26 const auto bc = ( c - b ).lengthSq();
33 const auto f =
cross( b - a, c - a ).lengthSq();
35 return std::numeric_limits<T>::infinity();
36 return ab * ca * bc / f;
59 const auto ab = ( b - a ).lengthSq();
60 const auto ca = ( a - c ).lengthSq();
61 const auto bc = ( c - b ).lengthSq();
68 const auto f =
cross( b - a, c - a ).lengthSq();
70 return ab * ca * bc / f;
80 const auto xabSq =
cross( a, b ).lengthSq();
90 const auto ab =
dot( a, b );
91 return ( bb * ( aa - ab ) * a + aa * ( bb - ab ) * b ) / ( 2 * xabSq );
114 const auto rr =
sqr( radius );
116 if ( rr < circRadSq )
119 const auto x = std::sqrt( rr - circRadSq );
120 const auto xn = x *
normal( a, b, c );
122 centerPos = circCenter + xn;
123 centerNeg = circCenter - xn;
136 const auto ab = ( b - a ).
length();
137 const auto ca = ( a - c ).
length();
138 const auto bc = ( c - b ).
length();
139 if ( ab <= 0 || ca <= 0 || bc <= 0 )
141 const auto f =
cross( b - a, c - a ).length();
142 return f * std::min( { ab, ca, bc } ) / ( ab * ca * bc );
162 const auto bc = ( c - b ).
length();
163 const auto ca = ( a - c ).
length();
164 const auto ab = ( b - a ).
length();
165 auto halfPerimeter = ( bc + ca + ab ) / 2;
166 auto den = 8 * ( halfPerimeter - bc ) * ( halfPerimeter - ca ) * ( halfPerimeter - ab );
168 return std::numeric_limits<T>::max();
170 return bc * ca * ab / den;
180 return cross( t[1] - t[0], t[2] - t[0] );
190 return cross( q, r );
200 return cross( q - p, r - p );
220 return normal( q - p, r - p );
230 return normal( t[1] - t[0], t[2] - t[0] );
248[[nodiscard]]
inline T
dblArea(
const Triangle3<T> & t )
280 return std::abs(
cross( q - p, r - p ) );
300 const auto c = ( t[0] + t[1] + t[2] ) / T(3);
303 for (
int i = 0; i < 3; ++i )
305 const auto sq = ( t[i] - c ).lengthSq();
306 if ( longestSq >= sq )
311 const auto d = ( t[longest] - c ).normalized();
315 for (
int i = 0; i < 3; ++i )
316 res[i] = c + d *
dot( d, t[i] - c );
328 const auto c = ( t[0] + t[1] + t[2] ) / T(3);
330 for (
int i = 0; i < 3; ++i )
331 res[i] = t[i] - n *
dot( n, t[i] - c );
350 return dot( edgeDir,
cross( leftNorm, rightNorm ) );
364 return dot( leftNorm, rightNorm );
381 return std::atan2( sin, cos );
400 const auto aa =
sqr( a );
401 const auto y = ( aa -
sqr( b ) +
sqr( c ) ) / ( 2 * c );
402 const auto yy =
sqr( y );
405 const auto x = std::sqrt( aa - yy );
426 auto y = ( p->x * p1->y - p1->x * p->y ) / ( p->x - p1->x );
427 if ( y < 0 || y > c )
429 return ( *p - *p1 ).length();
441 const T den = ( a + b + c ) * ( b + c - a );
443 return std::numeric_limits<T>::infinity();
444 const T num = ( a + c - b ) * ( a + b - c );
456[[nodiscard]]
inline T
cotan(
const Triangle3<T> & t, T absMaxVal = std::numeric_limits<T>::max() )
458 auto a = t[0] - t[2];
459 auto b = t[1] - t[2];
460 auto nom =
dot( a, b );
461 auto den =
cross( a, b ).length();
462 if ( fabs( nom ) >= absMaxVal * den )
463 return absMaxVal *
sgn( nom );
474[[nodiscard]]
inline T
cotan( T a, T b, T c )
476 const T den = ( a + b + c ) * ( b + c - a );
478 return -std::numeric_limits<T>::infinity();
479 const T num = ( a + c - b ) * ( a + b - c );
481 return std::numeric_limits<T>::infinity();
482 const auto tanSq = num / den;
483 return ( 1 - tanSq ) / ( 2 * std::sqrt( tanSq ) );
494 const auto bb =
dot( b, b );
495 const auto bc =
dot( b, c );
496 const auto cc =
dot( c, c );
497 const auto det = bb * cc - bc * bc;
500 const auto kb = ( 1 / det ) * ( cc * vb - bc * vc );
501 const auto kc = ( 1 / det ) * (-bc * vb + bb * vc );
502 return kb * b + kc * c;
524 const auto gradSq = grad.
lengthSq();
527 const auto d = c - b;
529 const auto gort = d - (
dot( d, grad ) / gradSq ) * grad;
530 const auto god =
dot( gort, d );
533 const auto gob = -
dot( gort, b );
534 if ( gob <= 0 || gob >= god )
536 const auto a = gob / god;
537 assert( a < std::numeric_limits<T>::max() );
538 const auto ip = a * c + ( 1 - a ) * b;
539 if (
dot( grad, ip ) >= 0 )
557 if ( !grad.has_value() )
559 auto gradSq = grad->lengthSq();
562 return sqrt( 1 - gradSq ) *
normal( b, c ) - *grad;
Plane3
Definition MRMeshFwd.h:394
float area(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns the area of given face
Definition MRMeshMath.h:168
constexpr T sqr(T x) noexcept
squared value
Definition MRMeshFwd.h:768
float dihedralAngleSin(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
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
Vector3< T > circumcircleCenter(const Vector3< T > &a, const Vector3< T > &b)
Computes the center of the the triangle's 0AB circumcircle.
Definition MRTriMath.h:78
std::optional< T > findTriExitPos(const Vector3< T > &b, const Vector3< T > &c, const Vector3< T > &grad)
Definition MRTriMath.h:522
std::optional< T > quadrangleOtherDiagonal(T a, T b, T c, T a1, T b1)
Definition MRTriMath.h:416
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:298
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...
T tanSqOfHalfAngle(T a, T b, T c)
Definition MRTriMath.h:439
Triangle3< T > triangleWithNormal(const Triangle3< T > &t, const Vector3< T > &n)
Definition MRTriMath.h:326
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
float dihedralAngleCos(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
constexpr int sgn(T x) noexcept
sign of given value in { -1, 0, 1 }
Definition MRMeshFwd.h:772
std::optional< Vector3< T > > gradientInTri(const Vector3< T > &b, const Vector3< T > &c, T vb, T vc)
Definition MRTriMath.h:492
Triangle3< double > Triangle3d
Definition MRMeshFwd.h:471
float circumcircleDiameter(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns circumcircle diameter of given mesh triangle
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:575
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:110
std::optional< Vector3< T > > tangentPlaneNormalToSpheres(const Vector3< T > &b, const Vector3< T > &c, T rb, T rc)
Definition MRTriMath.h:554
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
MR_BIND_TEMPLATE(std::pair< Vector3f, TriPointf > closestPointInTriangle(const Vector3f &p, const Vector3f &a, const Vector3f &b, const Vector3f &c))
T minTriangleAngle(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
Definition MRTriMath.h:149
Triangle3< float > Triangle3f
Definition MRMeshFwd.h:470
std::optional< Vector2< T > > posFromTriEdgeLengths(T a, T b, T c)
Definition MRTriMath.h:391
float circumcircleDiameterSq(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns squared circumcircle diameter of given mesh triangle
float cotan(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId ue)
Definition MRMeshMath.h:315
T lengthSq() const
Definition MRVector3.h:68
float dihedralAngle(const MeshTopology &topology, const VertCoords &points, UndirectedEdgeId e)
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:238
length
Definition MRObjectDimensionsEnum.h:17
@ normal
Definition MRUnits.h:45
T mincircleDiameterSq(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
Definition MRTriMath.h:57
T minTriangleAngleSin(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
Definition MRTriMath.h:134
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRVector2.h:29
T cross(const Vector2< T > &a, const Vector2< T > &b)
cross product
Definition MRVector2.h:160
Definition MRVector3.h:33