Detect when an object is inside another.

I’m trying to achieve something which I am not sure is possible. I would like to check if an object is completely inside another object (basically another image) and not just touching at the edges slightly. Maybe it’s easier than I thought.

I appreciate the help.

Cheers.

Hey dip,

are the objects rotated or not?

If not, you can use this function to check if one rectangle is inside another one.

--[[-------------------------------------------------------------------------------------------------------- Estimates if one rectangle (R1) with the center point R and a given width and height is completly inside another rectangle (R2) @param R1x, R1y - x and y cordinates of the first rects center point @param R1w, R1h - width and height of the first rect @param R2x, R2y - x and y cordinates of the second rects center point @param R2w, R2h - width and height of the second rect @return - true, if the first rect is completly inside the second one ----------------------------------------------------------------------------------------------------------]] local function rectInRect(R1x, R1y, R1w, R2h, R2x, R2y, R2w, R2h) R1x, R1y = R1x - R1w\*0.5, R1y - R1h\*0.5 return (R1x \>= R2x and R1y \>= R2y and R1x + R1w \<= R2x + R2w and R1y + R1h \<= R2y + R2h) end

Wrong, very wrong sub-forum you are in.

@bgmadclown - Yes you are right, I normally don’t post threads here and don’t know why I did. Sorry for the mistake.

@torbenratzlaff - Thanks for the help, That is perfect to get going.

Moving to General

Hey dip,

are the objects rotated or not?

If not, you can use this function to check if one rectangle is inside another one.

--[[-------------------------------------------------------------------------------------------------------- Estimates if one rectangle (R1) with the center point R and a given width and height is completly inside another rectangle (R2) @param R1x, R1y - x and y cordinates of the first rects center point @param R1w, R1h - width and height of the first rect @param R2x, R2y - x and y cordinates of the second rects center point @param R2w, R2h - width and height of the second rect @return - true, if the first rect is completly inside the second one ----------------------------------------------------------------------------------------------------------]] local function rectInRect(R1x, R1y, R1w, R2h, R2x, R2y, R2w, R2h) R1x, R1y = R1x - R1w\*0.5, R1y - R1h\*0.5 return (R1x \>= R2x and R1y \>= R2y and R1x + R1w \<= R2x + R2w and R1y + R1h \<= R2y + R2h) end

Wrong, very wrong sub-forum you are in.

@bgmadclown - Yes you are right, I normally don’t post threads here and don’t know why I did. Sorry for the mistake.

@torbenratzlaff - Thanks for the help, That is perfect to get going.

Moving to General