// Returns a boolean that tells whether the point is inside a rectangle.
// (px , py) = Point to check
// (cx , cy) = lower left corner of the rect
// (ax , ay) = upper left corner
// (bx , by) = lower right corner
function IsPointInRect takes real px , real py , real cx , real cy , real ax , real ay , real bx , real by returns boolean
local real dot1 = (px-cx)*(ax-cx) + (py-cy)*(ay-cy)
local real dot2 = (ax-cx)*(ax-cx) + (ay-cy)*(ay-cy)
local real dot3 = (px-cx)*(bx-cx) + (py-cy)*(by-cy)
local real dot4 = (bx-cx)*(bx-cx) + (by-cy)*(by-cy)
return dot1 >= 0 and dot1 <= dot2 and dot3 >= 0 and dot3 <= dot4
endfunction
This is the system. I'd wait for a moderator to approve it as there may be some flaws in it.
rect
objects cannot be tilted and must have static orientation, either horizontal or vertical.Maker yours only works for horizontal/vertical rectangles.
function GetIsInOblong takes real x1, real x2, real x3, real y1, real y2, real y3, real width returns boolean
//x1,x2,y1,y2 refers to the beginning of the middle line of the oblong, x3 and y3 to the point that needs to be checked
local real a = 0.00
local real b = 0.00
local real lenght = SquareRoot((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1))
local integer e = 0
if x2-x1 == 0.00 then
set e = e + 1
endif
if y2-y1 == 0.00 then
set e = e + 2
endif
//In one of these cases we got oblongs parallel to the x or y axis, the orthognal counterpart will have a lenght of 1
//ths system defines a coordinate system of following vectors: the vector from P1 to P2 and its orthogonal counterpart
// a and b are the coordinates of point P3-P1 in this coordinate system
// P1 (x1/y1) is the origin of the coordinate system
//The lenght of the vectors and the coordinates are in indicator to check if the point is in the oblong or not.
if e > 0 then
if e == 1 then
set a = (y3 - y1) / (y1 - y2)
set b = x3 - x1
elseif e == 2 then
set a = (x3 - x1) / (x1 - x2)
set b = y3 - y1
else
return false
endif
else
set a = ((y3 - y1) / (y2 - y1) + (x3 - x1) / (x2 - x1)) / 2.00
set b = ((y3 - y1) / (y2 - y1) + (x3 - x1) / (x2 - x1)) / 2.00 / lenght
endif
return a <= 1 and a >= 0 and b <= width and b >= -1.00 * width
endfunction
function GetIsInOblong takes real x1, real x2, real x3, real y1, real y2, real y3, real width returns boolean
//x1,x2,y1,y2 refers to the beginning of the middle line of the oblong, x3 and y3 to the point that needs to be checked
local real a = 0.00
local real b = 0.00
local real lenght = SquareRoot((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1))
local integer e = 0
if x2-x1 == 0.00 then
set e = e + 1
endif
if y2-y1 == 0.00 then
set e = e + 2
endif
//In one of these cases we got oblongs parallel to the x or y axis, the orthognal counterpart will have a lenght of 1
//ths system defines a coordinate system of following vectors: the vector from P1 to P2 and its orthogonal counterpart
// a and b are the coordinates of point P3-P1 in this coordinate system
// P1 (x1/y1) is the origin of the coordinate system
//The lenght of the vectors and the coordinates are in indicator to check if the point is in the oblong or not.
if e > 0 then
if e == 1 then
set a = (y3 - y1) / (y1 - y2)
set b = x3 - x1
elseif e == 2 then
set a = (x3 - x1) / (x1 - x2)
set b = y3 - y1
else
return false
endif
else
set b = ((y3 - y1) * (x2 - x1) - (x3 - x1) * (y2 - y1)) / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
set a = (x3 - x1 - (b * (y2 - y1))) / (x2 - x1)
set b = b / lenght
endif
return a <= 1 and a >= 0 and b <= width and b >= -1.00 * width
endfunction