code: public static Vector3f findClosestPointOnLineSegment(float aX, float aY, float aZ, float bX, float bY, float bZ, float pX, float pY, float pZ, Vector3f result) {
          float abX = bX - aX, abY = bY - aY, abZ = bZ - aZ;
          float t = ((pX - aX) * abX + (pY - aY) * abY + (pZ - aZ) * abZ) / (abX * abX + abY * abY + abZ * abZ);
          if (t < 0.0f) t = 0.0f;
          if (t > 1.0f) t = 1.0f;
          result.x = aX + t * abX;
          result.y = aY + t * abY;
          result.z = aZ + t * abZ;
          return result;
      }
docs: Find the point on the given line segment which is closest to the specified point <code>(pX, pY, pZ)</code>, and store the result in <code>result</code>.
  
  @param aX
  the x coordinate of the first end point of the line segment
  @param aY
  the y coordinate of the first end point of the line segment
  @param aZ
  the z coordinate of the first end point of the line segment
  @param bX
  the x coordinate of the second end point of the line segment
  @param bY
  the y coordinate of the second end point of the line segment
  @param bZ
  the z coordinate of the second end point of the line segment
  @param pX
  the x coordinate of the point
  @param pY
  the y coordinate of the point
  @param pZ
  the z coordinate of the point
  @param result
  will hold the result
  @return result