float calcDistance(float x1, float y1, float x2, float y2, float x3, float y3)
{
float px = x2-x1;
float py = y2-y1;
float something = px*px + py*py;
float u = ((x3 - x1) * px + (y3 - y1) * py) / something;
if(u > 1){
u = 1;
}else if(u < 0)
{
u = 0;
}
float x = x1 + u * px;
float y = y1 + u * py;
float dx = x - x3;
float dy = y - y3;
float dist = sqrt(dx*dx + dy*dy);
return dist;
}
댓글
댓글 쓰기