public float [] minDistancePoint (float x,float y,float pt1_x,float pt1_y,float pt2_x,float pt2_y){

    	   float distance = calculateDistance(pt1_x,pt1_y,pt2_x,pt2_y);
    	   //Two points of the line segment are the same
    	   if (distance == 0) return new float [] {pt1_x,pt1_y,0};

    	   float t = ((x - pt1_x) * (pt2_x - pt1_x) + (y - pt1_y) * (pt2_y - pt1_y)) / distance;
    	   if (t < 0) return new float [] {pt1_x,pt1_y,t}; //Point projection goes beyond pt1
    	   if (t > 1) return new float [] {pt2_x,pt2_y,t}; //Point projection goes beyond pt2

    	   //Otherwise, point projection lies on the line somewhere
    	    float minX = pt1_x + t*(pt2_x-pt1_x);
    	    float minY = pt1_y + t*(pt2_y-pt1_y);
    	    return new float [] {minX,minY,t};
    	}