thirdparty/bullet3/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp
void btNearestPointInLineSegment(const btVector3& point, const btVector3& line0, const btVector3& line1, btVector3& nearestPoint)
{
	btVector3 lineDelta = line1 - line0;

	// Handle degenerate lines
	if (lineDelta.fuzzyZero())
	{
		nearestPoint = line0;
	}
	else
	{
		// [0..1] delta
		btScalar delta = (point - line0).dot(lineDelta) / (lineDelta).dot(lineDelta);

		// Clamp the point to conform to the segment's endpoints
		if (delta < 0)
			delta = 0;
		else if (delta > 1)
			delta = 1;

		nearestPoint = line0 + lineDelta * delta;
	}
}
// Given a point and a line segment (defined by two points), compute the closest point
// in the line.  Cap the point at the endpoints of the line segment.
Given a point and a line segment (defined by two points), compute the closest point
in the line.  Cap the point at the endpoints of the line segment.
Given a point and a line segment ( defined by two points ) compute the closest point in the line . Cap the point at the endpoints of the line segment .
void btNearestPointInLineSegment(const btVector3& point, const btVector3& line0, const btVector3& line1, btVector3& nearestPoint)
{
	btVector3 lineDelta = line1 - line0;
	if (lineDelta.fuzzyZero())
	{
		nearestPoint = line0;
	}
	else
	{
		btScalar delta = (point - line0).dot(lineDelta) / (lineDelta).dot(lineDelta);
		if (delta < 0)
			delta = 0;
		else if (delta > 1)
			delta = 1;
		nearestPoint = line0 + lineDelta * delta;
	}
}
void btNearestPointInLineSegment ( const btVector3 & point , const btVector3 & line0 , const btVector3 & line1 , btVector3 & nearestPoint ) { btVector3 lineDelta = line1 - line0 ; if ( lineDelta . fuzzyZero ( ) ) { nearestPoint = line0 ; } else { btScalar delta = ( point - line0 ) . dot ( lineDelta ) / ( lineDelta ) . dot ( lineDelta ) ; if ( delta < 0 ) delta = 0 ; else if ( delta > 1 ) delta = 1 ; nearestPoint = line0 + lineDelta * delta ; } }
Given a point and a line segment (defined by two points), compute the closest point
in the line.
Given a point and a line segment ( defined by two points ) compute the closest point in the line .
// Handle degenerate lines // [0..1] delta // Clamp the point to conform to the segment's endpoints