T
The Conqueror
Guest
I was reading this tutorial Algorithm Tutorials
but I couldn't understand this piece of code. (Line-Point distance). Could someone explain this in a simpler way?
but I couldn't understand this piece of code. (Line-Point distance). Could someone explain this in a simpler way?
Code:
//Compute the distance from AB to C
//if isSegment is true, AB is a segment, not a line.
double linePointDist(int[] A, int[] B, int[] C, boolean isSegment){
double dist = cross(A,B,C) / distance(A,B);
if(isSegment){
int dot1 = dot(A,B,C);
if(dot1 > 0)return distance(B,C);
int dot2 = dot(B,A,C);
if(dot2 > 0)return distance(A,C);
}
return abs(dist);
}