pub fn closest_point_to_point(self, point: Vec3f) -> (f32, Vec3f) {
        let a = self.start;
        let b = self.end;

        let ab = b - a;
        // Project point onto ab, but deferring divide by ab.dot(ab)
        let t = (point - a).dot(ab);
        if t <= 0.0f32 {
            // point projects outside the [a,b] interval, on the a
            // side; clamp to a
            (0.0f32, a)
        } else {
            // Always nonnegative since denom = ||ab|| ∧ 2
            let denom = ab.dot(ab);
            if t >= denom {
                // point projects outside the [a,b] interval, on the b
                // side; clamp to b
                (1.0f32, b)
            } else {
                // point projects inside the [a,b] interval; must do
                // deferred divide now
                let t = t / denom;
                (t, a + ab * t)
            }
        }
    }
/// Find the point on the segment closest to the input point. The
/// return value contains both the parametric and actual location
/// of the closest point.
///
/// Adapted from "Real-Time Collision Detection" by Christer
/// Ericson, published by Morgan Kaufmann Publishers, Copyright
/// 2005 Elsevier Inc
Find the point on the segment closest to the input point. The
return value contains both the parametric and actual location
of the closest point.

Adapted from "Real-Time Collision Detection" by Christer
Ericson, published by Morgan Kaufmann Publishers, Copyright
2005 Elsevier Inc
Find the point on the segment closest to the input point . The return value contains both the parametric and actual location of the closest point . Adapted from " Real - Time Collision Detection " by Christer Ericson published by Morgan Kaufmann Publishers Copyright 2005 Elsevier Inc
pub fn closest_point_to_point(self, point: Vec3f) -> (f32, Vec3f) {
        let a = self.start;
        let b = self.end;
        let ab = b - a;
        // Project point onto ab, but deferring divide by ab.dot(ab)
        let t = (point - a).dot(ab);
        if t <= 0.0f32 {
            // point projects outside the [a,b] interval, on the a
            // side; clamp to a
            (0.0f32, a)
        } else {
            // Always nonnegative since denom = ||ab|| ∧ 2
            let denom = ab.dot(ab);
            if t >= denom {
                // point projects outside the [a,b] interval, on the b
                // side; clamp to b
                (1.0f32, b)
            } else {
                // point projects inside the [a,b] interval; must do
                // deferred divide now
                let t = t / denom;
                (t, a + ab * t)
            }
        }
    }
pub fn closest_point_to_point ( self , point : Vec3f ) -> ( f32 , Vec3f ) { let a = self . start ; let b = self . end ; let ab = b - a ; // Project point onto ab, but deferring divide by ab.dot(ab) let t = ( point - a ) . dot ( ab ) ; if t <= 0.0f32 { // point projects outside the [a,b] interval, on the a // side; clamp to a ( 0.0f32 , a ) } else { // Always nonnegative since denom = ||ab|| ∧ 2 let denom = ab . dot ( ab ) ; if t >= denom { // point projects outside the [a,b] interval, on the b // side; clamp to b ( 1.0f32 , b ) } else { // point projects inside the [a,b] interval; must do // deferred divide now let t = t / denom ; ( t , a + ab * t ) } } }
Find the point on the segment closest to the input point.
Find the point on the segment closest to the input point .
self
point
Vec3f
self
point
Vec3f