//*********************************
//Geometrical Checks
//by Daelin
//
//CONTAINS THE FOLLOWING IMPORTANT FUNCTIONS
//1. IsPointInTriangle - Determines if a point is inside a triangle, given the vertices of the triangle
//and the coordinates of the point (which are x,y)
//2. IsPointInRectangle - Determines if a point is inside a convex quadrilater, given its vertices
//and the coordinates of the point (which are x,y)
//3. IsPointInCircle - Determines if a point is inside a circle, given the coordinates of its center
//(xC, yC), its radius, and the coordinates of the point (x,y)
//4. IsPointInCircleSector - Determines if a point is inside a sector of a circle, given the circle
//and the point just like in the previous function, but also the angles between which the sector is
//situated (angleA, angleB).
//*********************************
function GetAngleBetweenPoints takes real x1, real y1, real x2, real y2 returns real
return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction
function PolarProjectionX takes real x, real distance, real angle returns real
return x+distance*Cos(angle * bj_DEGTORAD)
endfunction
function PolarProjectionY takes real y, real distance, real angle returns real
return y+distance*Sin(angle * bj_DEGTORAD)
endfunction
function IsPointInTriangle takes real x1, real y1, real x2, real y2, real x3, real y3, real x, real y returns boolean
local real calc1 = (y-y1)*(x2-x1) - (x-x1)*(y2-y1)
local real calc2 = (y-y3)*(x1-x3) - (x-x3)*(y1-y3)
local real calc3 = (y-y2)*(x3-x2) - (x-x2)*(y3-y2)
return (calc1*calc2>0) and (calc3*calc2>0)
endfunction
function IsPointInRectangle takes real x1, real y1, real x2, real y2, real x3, real y3, real x4, real y4, real x, real y returns boolean
return IsPointInTriangle(x1,y1,x2,y2,x3,y3,x,y) or IsPointInTriangle(x4,y4,x2,y2,x3,y3,x,y) or IsPointInTriangle(x1,y1,x4,y4,x3,y3,x,y) or IsPointInTriangle(x1,y1,x2,y2,x4,y4,x,y)
endfunction
function IsPointInCircle takes real xC, real yC, real radius, real x, real y returns boolean
local real xx = xC-x
local real yy = yC-y
return xx*xx + yy*yy<=radius*radius
endfunction
function IsPointInCircleSector takes real xC, real yC, real radius, real x, real y, real angleA, real angleB returns boolean
local real angle = GetAngleBetweenPoints(xC,yC,x,y)
local real aux
if angleA>angleB then
set aux=angleA
set angleA=angleB
set angleB=aux
endif
return IsPointInCircle(xC,yC,radius,x,y) and angle>=angleA and angle<=angleB
endfunction