Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Fastest way to see if a shape is fully contained inside another shape  (Read 1553 times)
0 Members and 1 Guest are viewing this topic.
Offline Sanzeinga

Senior Newbie





« Posted 2009-04-08 22:02:32 »

(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.
Offline appel

JGO Wizard


Medals: 51
Projects: 4


I always win!


« Reply #1 - Posted 2009-04-08 22:22:15 »

I believe that if you have a:

hugeCircle

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


1  
2  
3  
4  
5  
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.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline DzzD
« Reply #2 - Posted 2009-04-08 22:32:57 »

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 ?





Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Sanzeinga

Senior Newbie





« Reply #3 - Posted 2009-04-08 22:36:28 »

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
Offline DzzD
« Reply #4 - Posted 2009-04-08 22:48:25 »

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...


Offline appel

JGO Wizard


Medals: 51
Projects: 4


I always win!


« Reply #5 - Posted 2009-04-08 22:57:32 »

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

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.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (18 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (45 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!