Continuing the experimentation I’ve started with spheres merging (some transparency issues there), I’m trying to detect if two spheres are intersecting so I can (hopefully) merge them.
For testing I make 2 spheres, add bounding spheres to them and check if they intersect. Problem is, they seem to always intersect (at least partially).
Here’s what the output is telling me:
—
Merging spheres.
Sphere’s (ORANGY) radius = 5.0 Bounding sphere’s radius = 5.00001
Sphere’s center = (0.0, 8.0, 0.0) Bounding sphere’s center = (0.0, -8.1340875E-7, -2.3841858E-7)
Bounding Sphere intersecting with other sphere’s (PINKY) bounding volume? true
Getting collision between ORANGY and PINKY
We have 152 collisions.
Collisions list:
Collision at null
[ snipped 150x ]
Collision at null
Sphere’s (PINKY) radius = 5.0 Bounding sphere’s radius = 5.00001
Sphere’s center = (0.0, -8.0, 0.0) Bounding sphere’s center = (0.0, -8.1340875E-7, -2.3841858E-7)
Bounding Sphere intersecting with other sphere’s (ORANGY) bounding volume? true
Getting collision between PINKY and ORANGY
We have 152 collisions.
Collisions list:
Collision at null
[ snipped 150x ]
Collision at null
—
The merging code that spews the above:
[java]
private void mergeSpheres() {
System.out.println(“Merging spheres.”);
for (int i = 0; i < sphList.size(); i++) {
Geometry s1 = sphList.get(i);
for (Geometry s : sphList) {
if (s1 != s) {
boolean intersect = s1.getModelBound().intersectsSphere(((BoundingSphere) s.getModelBound()));
float radius = ((BoundingSphere) s1.getModelBound()).getRadius();
float spRad = ((Sphere) s1.getMesh()).radius;
//
System.out.println("nSphere's (" + s1.getName() + ") radius = " + spRad + " Bounding sphere's radius = " + radius);
System.out.println("Sphere's center = " + s1.getWorldTranslation() + " Bounding sphere's center = " + s1.getModelBound().getCenter());
System.out.println("Bounding Sphere intersecting with other sphere's (" + s.getName() + ") bounding volume? " + intersect);
System.out.println("Getting collision between " + s1.getName() + " and " + s.getName());
//
CollisionResults colRes = new CollisionResults();
int coll = s1.collideWith(s.getModelBound(), colRes);
if (coll > 0) {
System.out.println("We have " + coll + " collisions.");
mergeSpheres(s1, s, colRes);
} else {
System.out.println("We have no collision.");
}
}
}
}
}
private void mergeSpheres(Geometry g1, Geometry g2, CollisionResults colRes) {
System.out.println("Collisions list: n");
for (int i = 0; i < colRes.size() ; i++) {
CollisionResult cr = colRes.getCollision(i);
System.out.println("Collision at " + cr.getContactPoint());
}
}
[/java]
---
Finally the scene with the spheres + bounding spheres.

http://www.disenthral.com/files/collisionspheres.png
---
Ultimately the goal is to merge spheres into one mesh, if possible, to delineate the frontiers of an alien race in the game world where each star system (point sprite) has a sphere of X radius around it.