Programmers help me!

1 Name: Anonymous 2018-12-05 20:52
! How can i check if the smaller rectangle is fully inside the bigger rectangle. I know the corner points of every rectangle. Pic related
2 Name: Anonymous 2018-12-05 21:03
If they're diagonal like that, then rotate them first so the rectangles are orthogonal.

Once you've got two orthogonal rectangles, just check that each point of the inner rectangle is inside the outer rectangle.

Outer rect corners: Out1(x, y) Out2(x, y) Out3(x, y) Out4(x, y)

Inner rect corners: In1(x, y) In2(x, y) In3(x, y) In4(x, y)

if (
(In1x > Out1x && In1x < Out2x &&
In1y > Out1y && In1y < Out3y) &&
(In2... check x and y) &&
(In3... check x and y) &&
(In4... check x and y)

And then if you want to check if either is inside the other, then do the same again with the Ins and Outs reversed.

It's a big messy conditional, but that's how you've got to check them, unless you want to abstract out some sort of boundary check method to compare two points to make the calls line up all neat.

Also, it helps conceptually to think about the one dimensional version, then scale it up to 2D.
3 Name: Anonymous 2018-12-05 21:12
What if the rectangles have different angles? Does it still work?
4 Name: Anonymous 2018-12-05 21:42
If your rectangles are rotated at arbitrary angles, then you've got a generalized polygon collision detection problem.

It's not fun to solve.

You're better off breaking the shapes down into smaller rectangles and comparing them. If you need pixel perfect, well, pixels are tiny rectangles too.

Let me see if I have some code saved somewhere...
5 Name: Anonymous 2018-12-05 21:48
Oh boy..
6 Name: Anonymous 2018-12-05 21:53
if they are rotated by an angle- wouldn't checking for intercepts work? just check if any of the 4 lines (sides of rectangles) intercept any of the other 4 lines....
7 Name: Anonymous 2018-12-05 21:55
why do you need programmers?
8 Name: Anonymous 2018-12-05 21:59
Yes. I have code that does this... but I can't put the pastebins up here. /prog/ is retarded and thinks they're spam no matter now I post them.

Actually. Let me try this-
9 Name: Anonymous 2018-12-05 22:01
The line intersection method does not work for polygons that are concave, only convex.

Otherwise yes... and I think that's what my code does, but I wrote it a long time ago, so I really don't remember.
10 Name: Anonymous 2018-12-05 22:04
Everybody needs programmers, whether they know it or not. Autists unite.
11 Name: Anonymous 2018-12-05 22:09
This is what the code looks like when run.
12 Name: Anonymous 2018-12-05 22:11
And the background turns blue when there is a collision
13 Name: Anonymous 2018-12-05 22:18
Here you go. My code does this. Enjoy.

If this is homework, good luck with school. If you're making a game, this is just the start of your pain.
14 Name: Anonymous 2018-12-05 22:25
Mathematicians are welcome too, its just that programmers encounter these problems frequently
15 Name: Anonymous 2018-12-05 22:37
Thanks ill look at it :)
16 Name: Anonymous 2018-12-05 22:56
No problem. Hope it helps you. Don't forget, it won't work if you draw a polygon with a concave feature.

Leave this field blank: