MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / mShortestSegmentBetweenLines

Function mShortestSegmentBetweenLines

Engine/source/math/mathUtils.cpp:816–838  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

814//-----------------------------------------------------------------------------
815
816void mShortestSegmentBetweenLines( const Line &line0, const Line &line1, LineSegment *outSegment )
817{
818 // compute intermediate parameters
819 Point3F w0 = line0.origin - line1.origin;
820 F32 a = mDot( line0.direction, line0.direction );
821 F32 b = mDot( line0.direction, line1.direction );
822 F32 c = mDot( line1.direction, line1.direction );
823 F32 d = mDot( line0.direction, w0 );
824 F32 e = mDot( line1.direction, w0 );
825
826 F32 denom = a*c - b*b;
827
828 if ( denom > -0.001f && denom < 0.001f )
829 {
830 outSegment->p0 = line0.origin;
831 outSegment->p1 = line1.origin + (e/c)*line1.direction;
832 }
833 else
834 {
835 outSegment->p0 = line0.origin + ((b*e - c*d)/denom)*line0.direction;
836 outSegment->p1 = line1.origin + ((a*e - b*d)/denom)*line1.direction;
837 }
838}
839
840//-----------------------------------------------------------------------------
841

Callers 3

generateMethod · 0.85
on3DMouseDownMethod · 0.85
on3DMouseDraggedMethod · 0.85

Calls 1

mDotFunction · 0.70

Tested by

no test coverage detected