I've been trying to make a function that calculates the distance between a point and a line. I know one point from a line, let's call it (xl, yl), and the point whose distance I need to calculate is (xp, yp). I also know the angle of the line (just called angle). So the equation of the line is
y-yl = tan (angle) * (x-xl), in normal form
-tan (angle) * x + y - yl + tan (angle) * xl = 0
The distance between line and point can be calculated with formula
|a*x0 + b*y0 + c| / sqrt (a^2 + b^2)
in this case:
|-tan (angle) * xp + yp - yl + tan (angle) * xl| / sqrt ( (tan (angle))^2 + 1^2))
Here's my function:
The problem is that this function doesn't return the correct value.
y-yl = tan (angle) * (x-xl), in normal form
-tan (angle) * x + y - yl + tan (angle) * xl = 0
The distance between line and point can be calculated with formula
|a*x0 + b*y0 + c| / sqrt (a^2 + b^2)
in this case:
|-tan (angle) * xp + yp - yl + tan (angle) * xl| / sqrt ( (tan (angle))^2 + 1^2))
Here's my function:
JASS:
function DistancePointLine takes location pointInLine, location pointToCheck, real angle returns real
local real xl = GetLocationX (pointInLine)
local real yl = GetLocationY (pointInLine)
local real xp = GetLocationX (pointToCheck)
local real yp = GetLocationY (pointToCheck)
local real a = Tan (angle)
return RAbsBJ ((-a*xp + yp + a*xl - yl) / SquareRoot (Pow (a, 2) + 1))
endfunction