| 792 | //----------------------------------------------------------------------------- |
| 793 | |
| 794 | Point3F 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 |
no test coverage detected