Hello world - Formule Utili
//Distanza tra due punti
--------------------------------------------------------------
double Distance(Vect2d p1, Vect2d p2)
{
double dx = p2.x - p1.x;
double dy = p2.y - p1.y;
return sqrt((double)dx*dx + dy*dy);
};
//Distanza tra un punto e un segmento
--------------------------------------------------------------
double DistanceToLine(Vect2d lineP1, Vect2d lineP2, Vect2d point)
{
double normalLength = _hypot(lineP2.x - lineP1.x, lineP2.y - lineP1.y);
double distance = (double)((point.x - lineP1.x) * (lineP2.y - lineP1.y) - (point.y - lineP1.y) * (lineP2.x - lineP1.x)) / normalLength;
return abs(distance);
}
--------------------------------------------------------------
double Distance(Vect2d p1, Vect2d p2)
{
double dx = p2.x - p1.x;
double dy = p2.y - p1.y;
return sqrt((double)dx*dx + dy*dy);
};
//Distanza tra un punto e un segmento
--------------------------------------------------------------
double DistanceToLine(Vect2d lineP1, Vect2d lineP2, Vect2d point)
{
double normalLength = _hypot(lineP2.x - lineP1.x, lineP2.y - lineP1.y);
double distance = (double)((point.x - lineP1.x) * (lineP2.y - lineP1.y) - (point.y - lineP1.y) * (lineP2.x - lineP1.x)) / normalLength;
return abs(distance);
}
Commenti
Posta un commento