Re: looking for suggestions to detect collisions in a java.awt.Graphics2D plane
"Mark Bennett" <[email protected]>
| Newsgroups | gmane.org.user-groups.trijug.juglist |
|---|---|
| Message-ID | <[email protected]> |
First it sounds as if doesn't matter if the the collision occurs before the time period is over. If not, and there is a finite and relatively low number of pixels perhaps perhaps you can hash out location the 15 pixes that get occupied for each one. Just check to see if the 15 pixels are already occupied as you step through the critters. The calculation is N*15. Mark Mark On Dec 1, 2007 10:37 PM, Mocky Habeeb <[email protected]> wrote: > Instead of using the area for collision detection try using the distance > between center points and compare that to the sum of the radii. Also it > would be helpful if you could find a way to only compare on object to those > that are close by. Overlapping grids is one option, storing your objects in > a tree structure sorted by position is another. > > > On Dec 1, 2007 8:31 PM, Richard O. Hammer <[email protected]> wrote: > > > I am writing an agent-based simulation in Java and I am looking for > > suggestions on how I can detect collisions between my critters as they > > move about on a two-dimensional plane. These critters simulate living > > things (people perhaps) all continuously moving about, but no two of > > them should be able to occupy the same space at the same time. > > > > I have a way to detect collisions which works okay for small N, but the > > required computation is N-squared, it increases with the square of the > > number of critters, and I want to find better. > > > > Let me describe more specifically: The GUI is being drawn with Java > > Swing. Each critter is circle shaped, a java.awt.geom.Area constructed > > with a java.awt.geom.Ellipse2D, and 15 pixels in diameter. In each > > increment of time in the simulation each critter can move some distance > > in some random direction. > > > > To compute the move for each critter first I create the proposed Area > > that will be occupied if the move succeeds without collision, by calling > > the Area method createTransformedArea(AffineTransform). Then I test to > > see if the proposed Area is already occupied by any other critter's Area > > > > by looping through the other critters, subtracting each critter's area > > from the proposed area (with the Area.subtract() method). If the > > proposed area is not changed by this subtraction then there is no > > collision, and the proposed move is allowed. That works but it is > > N-squared. > > > > So I am looking for suggestions. > > > > One wishful idea I've had is to look at the color of the pixels in the > > proposed Area. The background in my simulation is all white, but the > > Critters and other things are non-white. So a proposed Area would be > > allowed if it was all white. But I don't know the way to learn that. > > Can someone tell me that? > > > > Thanks very much, > > Rich Hammer > > Hillsborough > > < http://richard-o-hammer.org/firm.model.html> > > > > > > > > > > _______________________________________________ > > Juglist mailing list > > [email protected] > > http://trijug.org/mailman/listinfo/juglist_trijug.org > > > > > > -- > Regards, > > Mocky > _______________________________________________ > Juglist mailing list > [email protected] > http://trijug.org/mailman/listinfo/juglist_trijug.org > > _______________________________________________ Juglist mailing list [email protected] http://trijug.org/mailman/listinfo/juglist_trijug.org