- Joined
- Feb 4, 2009
- Messages
- 1,314
Checks if a line (or line segment) given by the points (x1, y1) and (x2, y2) intersects a circle with center (h, k) and radius r
JASS:
library LineIntersectsCircle
function GetDistanceFromLineToPoint takes real x1, real y1, real x2, real y2, real h, real k returns real
local real r
local real distance = SquareRoot((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
if distance <= 0.00 then
//if points are the same the line would be a plane I guess
//but it's more useful this way
return SquareRoot((x1-h)*(x1-h)+(y1-k)*(y1-k))
endif
set r = (x2-x1)*(k-y1)-(h-x1)*(y2-y1)
if r < 0.00 then
return -r/distance
endif
return r/distance
endfunction
function IsLineIntersectingCircle takes real x1, real y1, real x2, real y2, real h, real k, real r returns boolean
return GetDistanceFromLineToPoint(x1, y1, x2, y2, h, k) <= r
endfunction
endlibrary
Attachments
Last edited: