Página 6
Reflections and point-collisions in 2D
Página 7
Índice
See this article in english 
Página 8
Convex Hull (Quick Hull)

Lo sentimos - la página solicitada no está disponible en castellano. Mostrando la versión : en

Distance between a point and a line

Alexander Hristov

 

The distance betwen a point P and a line AB is the length of the segment that crosses the line, is perpendicular to it, and passes through P:

Point to Line Distance

To compute it, assume that we have the locations of two points on the line: (x1,y1) and (x2,y2). In another article of this series, we saw that a vector v that is perpendicular to this line will have the following coordinates:

Point to Line Distance 1

The distance d is the length of the projection of vector AP onto this vector v:

Point to Line distance

And this projection in turn is given by:

Point to Line Distance

Here's a Java snippet that computes this distance:

 
  public double pointToLineDistance(Point A, Point B, Point P) {
    double normalLength = Math.sqrt((B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y));
    return Math.abs((P.x-A.x)*(B.y-A.y)-(P.y-A.y)*(B.x-A.x))/normalLength;
  }

 

 

Comentarios

 

Añadir Comentario

Nombre (opcional)
EMail (opcional, no se muestra)

Texto