Fastest way to see if a shape is fully contained inside another shape

(im using slick)
Im considering using a circular boundary for the playing field, as such im wondering if there is a way to check if a shape is fully contained within another shape.

  1. But before that, is there a better way to keep shapes(hitboxes) within a circular boundary?
  2. Is there a better method than taking the 4 corners of a rectangle and seeing if theyre all within a gigantic circle that is the playing field. This is my current idea but it involves having to make a rectangular “bounding hitbox” for every entity (probably bigger than the sprite ), including things that otherwise have circular hitboxes.

I believe that if you have a:

hugeCircle

and objectShape within that hugeCircle, and assuming all objectShapes start within that hugeCircle, you could do:

if(hugeCircle.intersects(objectShape)) {
  // objectShape is going out of hugeCircle
} else {
  // objectShape is still within hugeCircle
}

I believe Shape.intersects(Shape) does return false if a shape is fully within another shape. Only when the lines of the shapes intersect does it return true.

if you try to test if a shape is within a circle ? if so just verify the following

for all point p
(p.x-c.x)² +(p.y-c.y)²< circleRadius²

if true for all point the shape made by all p point is inside circle with the center cx,cy

but not sure it is what you want ?

appel is that true? Wouldn’t that mean a very fast moving small object ( a bullet with a tiny hitbox ) might move past the boundary in one instant and never “collide”
dzzd how does that work for a circle within a circle

if you have c1 and c2 with their respective radius r1 & r2

you just have to compute the distance between the two center (and compare to a circle centered on c2 with a smaller radius depending on the c1 radius r1*0.5)

if
(c1.x-c2.x)²+(c1.y-c2.y)²<(r2-r1*0.5)²
then
c1 is inside c2

how it works => it compute the distance between the two center c1 & c2 and see if it is greater then a circle with radius r2-r1/2 centered on c2

ps: verify this a little cause I may have do errors on the formula…

You could fix (somewhat) with AppGameContainer.setMaximumLogicUpdateInterval(int).

However, if the game bullet of size 10x10 moves super-fast, say 400 pixels per 1 delta, then it’s not possible to detect collision this way. You’ll need to find another way. One would be to check if the line composing of previous location and new location intersect any of the lines of the target shape.