Hi !
Featured games (87)
games approved by the League of Dukes
Games in Showcase (670)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (727)
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  
  collision detection for round objects  (Read 2857 times)
0 Members and 1 Guest are viewing this topic.
Offline wireless_whiz

Junior Newbie

Java games rock!

« Posted 2004-01-30 03:59:13 »

Hi, What would be the best way to handle collisions between circular images  i.e when the images are actually rectangular .png. I am looking at angular deflections based on the point of contact.

Offline JasonB

Junior Devvie

« Reply #1 - Posted 2004-01-30 08:22:03 »

This seems relevant:

Offline wireless_whiz

Junior Newbie

Java games rock!

« Reply #2 - Posted 2004-01-30 09:49:57 »

Thanks. I have actually worked out the physics mainly. I was wondering how to get the pixel coordinates on the circle for collision detection.

if geometrically calculating the collision how do you deal with the transparent region of the image.

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

JGO Coder

Got any cats?

« Reply #3 - Posted 2004-01-30 20:00:12 »

one traditional way to do this is with shadow masks.

You create one mask that is the projection of the pixels down to a line and do a shifted bitwise comapre aganst the other obejcts mask.  if it collids you then either use masks for each line or go straight to pixel comparison.

Most games however don't bother as collision within a few pixels is often good enough...

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Offline swpalmer

JGO Coder

Exp: 12 years

Where's the Kaboom?

« Reply #4 - Posted 2004-02-05 03:20:05 »

If these are perfect circles then a simple test of the square distance between the center of the circles is enough.
(dx*dx + dy*dy) <= (r1*r1 + r2*r2)

Offline Abuse

JGO Ninja

Medals: 48

falling into the abyss of reality

« Reply #5 - Posted 2004-02-05 06:34:28 »

something like this? :-


This isn't a perfect solution (infact, a perfect solution is damn near impossible to obtain)
It isn't particularly performance optimised either.
All the source is in there though - the bit you will prolly be interested in is the Particle.checkCollisions().

my reference for some of the code was here :-

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here!
Offline clevengr

Senior Newbie

Java games rock!

« Reply #6 - Posted 2004-03-19 21:58:59 »

Posted by: swpalmer Posted on: Feb 5th, 2004, 1:20am
If these are perfect circles then a simple test of the square distance between the center of the circles is enough.  
(dx*dx + dy*dy) <= (r1*r1 + r2*r2)

Actually I think this may be off by a bit.  You want to check if the distance between the centers is less than the sum of the radii, and do so by comparing their squares to avoid taking roots for efficiency. The left side is the square of the distance, but the right side is the sum of the squares of the radii -- not the square of the sum of the radii.
Somebody correct me if I'm wrong, but I think the RHS should be  (r1*r1 + 2*r1*r2 + r2*r2).

Minor point... unless your objects are penetrating each other and making your application look bad....
Offline polybios

Innocent Bystander

Java games rock!

« Reply #7 - Posted 2004-04-15 06:56:53 »

you're right, primary school math  Smiley Smiley Smiley Smiley
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

IanParcs (36 views)
2016-04-18 14:18:53

KaiHH (36 views)
2016-04-18 08:35:41

KaiHH (67 views)
2016-04-15 12:43:58

theagentd (67 views)
2016-04-14 02:16:17

theagentd (74 views)
2016-04-14 02:15:43

IanParcs (67 views)
2016-04-12 03:51:16

IanParcs (37 views)
2016-04-12 03:50:03

IanParcs (33 views)
2016-04-12 03:49:54

IanParcs (30 views)
2016-04-12 03:49:52

IanParcs (39 views)
2016-04-12 03:49:52
Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30 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‑
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!