Here is my rectangle and point datum and how the rectangle is setup:
point
var
x
y
New(_x, _y)
x = _x
y = _y
trig_rect
var
angle
point
tl//top left
tr//top right
br//bottom right
bl//bottom left
width
height
proc/pointInRect(_x, _y)
return [If the point is inside the rectangle return TRUE]
world/New()
..()
var/trig_rect/rect = loadGraphics(40, 110, 140)
proc/loadGraphics(angle, x, y, trig_rect/rectangle = null)
var
base_width = 40
base_height = 30
base_x = x
base_y = y
trig_rect/rect = new
rect.tl = new((angle + 90 == 90 || angle + 90 == 270 ? base_x : base_x + base_height * cos(angle + 90)), (angle + 90 == 180 || angle + 90 == 360 ? base_y : base_y + base_height * sin(angle + 90)))
rect.tr = new((angle == 90 || angle == 270 ? base_x : base_x + base_width * cos(angle)), (angle == 180 || angle == 360 ? base_y : base_y + base_width * sin(angle)))
rect.br = new((angle == 90 || angle == 270 ? base_x : base_x + base_width * cos(angle)), (angle == 180 || angle == 360 ? base_y : base_y + base_width * sin(angle)))
rect.bl = new(base_x, base_y)
rect.width = base_width
rect.height = base_height
rect.angle = angle
[code]
return rect
All the points for the rectangle are known when the rectangle is at any given angle.
If I understood your question correctly... to check if any pt is inside any convex polygon, consider this calculation:
|x1 y1 1|
|x2 y2 1|
|x3 y3 1|
Where the lines mean determinant. Given point P, if we feed it the following point sets: {tl, tr, P}, {tr, br, P}, {br, bl, P} and {bl, tl, P}, we know P is inside the body if all results are either positive or negative (to generalise for a polygon with a different amount of points, simply create these sets by choosing a point in the polygon and progressing clockwise). At least I'm pretty sure we do. Make sure you check!
edit: I should really double-check what I'm writing! In any case this should work.