MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / lineIsect

Function lineIsect

source/MRMesh/MRReducePath.cpp:31–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29// finds position x on line x*b intersected by line containing segment [c,d]
30template<typename T>
31static T lineIsect( const Vector2<T> & b, const Vector2<T> & c, const Vector2<T> & d )
32{
33 const auto c1 = cross( d, c );
34 const auto c2 = cross( c - b, d - b );
35 if ( c1 == 0 && c2 == 0 )
36 {
37 // special degenerate case
38 // either b==0 or c-d collinear to 0-b
39 const auto bb = dot( b, b ); // b magnitude squared
40 if ( bb == 0 )
41 return 0; // b==0, x is arbitrary, and we return x=0
42 return ( dot( c, b ) + dot( d, b ) ) / ( 2 * bb ); // both c and d lay on 0-b line so return c-d middle point relative to 0-b segment
43 }
44 const auto cc = c1 + c2;
45 if ( cc == 0 )
46 return 0; // degenerate case
47 return c1 / cc;
48}
49
50template<typename T>
51T shortestPathInQuadrangle( const Vector3<T>& a, const Vector3<T>& b, const Vector3<T>& c, const Vector3<T>& d )

Callers 2

shortestPathInQuadrangleFunction · 0.85
reducePathViaVertexFunction · 0.85

Calls 2

crossFunction · 0.70
dotFunction · 0.70

Tested by

no test coverage detected