Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (687)
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 2751 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: 42

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.

Dwinin (73 views)
2015-11-07 13:29:08

Rems19 (81 views)
2015-10-31 01:36:56

Rems19 (78 views)
2015-10-31 01:32:37

williamwoles (107 views)
2015-10-23 10:42:59

williamwoles (93 views)
2015-10-23 10:42:45

Jervac_ (111 views)
2015-10-18 23:29:12

DarkCart (135 views)
2015-10-16 00:58:11

KaiHH (117 views)
2015-10-11 14:10:14

KaiHH (157 views)
2015-10-11 13:26:18

BurntPizza (172 views)
2015-10-08 03:11:46
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

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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!