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

Function mClosestPointOnSegment

Engine/source/math/mathUtils.cpp:794–812  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

792//-----------------------------------------------------------------------------
793
794Point3F mClosestPointOnSegment( const Point3F &a, const Point3F &b, const Point3F &p )
795{
796 Point3F c = p - a; // Vector from a to Point
797 Point3F v = (b - a);
798 F32 d = v.len(); // Length of the line segment
799 v.normalize(); // Unit Vector from a to b
800 F32 t = mDot( v, c ); // Intersection point Distance from a
801
802 // Check to see if the point is on the line
803 // if not then return the endpoint
804 if(t < 0) return a;
805 if(t > d) return b;
806
807 // get the distance to move from point a
808 v *= t;
809
810 // move from point a to the nearest point on the segment
811 return a + v;
812}
813
814//-----------------------------------------------------------------------------
815

Callers 7

updatePriorityMethod · 0.85
_getWaterPlaneMethod · 0.85
clickOnLineMethod · 0.85
updateWindMethod · 0.85
extrudeShapeFromFaceMethod · 0.85
collideAxisGizmoMethod · 0.85
on3DMouseDraggedMethod · 0.85

Calls 3

mDotFunction · 0.70
lenMethod · 0.45
normalizeMethod · 0.45

Tested by

no test coverage detected