- Joined
- Feb 4, 2009
- Messages
- 1,314
We've got a line given by P1(x1, y1) and P2(x2, y2) as well as a ray given by P3(x3, y3) and angle a.
This function returns the distance from P3 to the intersection point.
The distance returned is negative if the ray points away from the line.
This function returns the distance from P3 to the intersection point.
The distance returned is negative if the ray points away from the line.
JASS:
library GetIntersectionDistance
function GetIntersectionDistance takes real x1, real y1, real x2, real y2, real x3, real y3, real a returns real
local real m = x1-x2
if m==0. then//avoid division by zero
return (x1-x3)/Cos(a)
endif
set m = (y1-y2)/m
if m==Tan(a) then//parallel (avoid division by zero again: Sin(a)-Tan(a)*Cos(a)=0)
return 0.
endif
return (m*(x3-x1)+y1-y3)/(Sin(a)-m*Cos(a))
endfunction
endlibrary
Attachments
Last edited: