出現場所
http://piza2.2ch.net/test/read.cgi/tech/990219336/825 double distance(double x0,double y0,double x1,double y1,double px,double 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(x c,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 ) ;
}