// //############################################################################# //############################################################################# // Scalar Stuff::Find_Closest_Approach( const Point3D& origin1, const Vector3D& velocity1, Point3D *result1, const Point3D& origin2, const Vector3D& velocity2, Point3D *result2, Scalar *time, bool *constant ) { Vector3D a,b; a.Subtract(origin1, origin2); b.Subtract(velocity1, velocity2); // //-------------------------------------------------------------------- // If the velocities are identical, any point will do for the test, so // simply return the difference between the starting points //-------------------------------------------------------------------- // Scalar d = b.GetLengthSquared(); if (Small_Enough(d)) { *constant = true; d = a.GetLength(); return d; } // //------------------------------------------------------------------------- // The velocities are not parallel, so figure out when the closest approach // is via the derivative //------------------------------------------------------------------------- // *constant = false; *time = (a * b) / -d; // //------------------------------------------------------ // Now, plot the resultant points of both line equations //------------------------------------------------------ // Vector3D closest; closest.AddScaled(a, b, *time); result1->AddScaled(origin1, velocity1, *time); result2->AddScaled(origin2, velocity2, *time); d = closest.GetLength(); return d; }