double distance(double x0,y0,x1,y1,px,py) //型指定省略
{
double xc=px-x1; //点を平行移動
double yc=py-y1;
double x2=x0-x1; //線分のもう一方の端を平行移動
double y2=y0-y1;
if (x2*xc+y2*yc <0) {
return hypot(xc,yc);
};
xc=px-x0;
yc=py-y0;
x2=x1-x0;
y2=y1-y0;
if(x2*xc+y2*yc <0){
return hypot(xc,yc);
};
return fabs(y2*xc-x2*yc)/hypot(x2,y2) ;
}