Guys and Girls,

I'm having some problems with the BoundingSphere object and the
combine/intersect methods. Maybe I have not fully understood what these
methods are intended for; I am trying to construct a BoundingSphere that
encloses a cloud of points in 3D. Occasionally (about 1 time in 3), the
BoundingSphere fails to enclose one of the points (and always only 1 of the
points). Am I missing something obvious here? As you can see the
BoundingSphere failed to enclose all of the points passed into the combine
method 5 times out of the first 15 attempts.

Has anyone else run into this, is there a workaround, or will I have abandon
the BoundingSphere object and write the code myself. Incidentally, I tested
the BoundingBox and it does not have this problem.

It appears that the BoundingSphere automatically moves its centre to
minimise the radius that it uses (a surprise to me), which could make
BoundingSpheres quite computationally costly...

Interestingly, the points that "intersect" failed on do not appear to be
outside the BoundingSphere! (??). Any comments?

G'luck with your endeavours,

Daniel Selman
Tornado Labs Ltd.

Email:   [EMAIL PROTECTED]
Web:     www.tornadolabs.com
Phone:   +44 (0131) 343 2513
Fax:     +44 07070 800 483


The output from the code I have enclosed below looks something like this
(yours will vary as the points are randomly generated):

TestBoundingSphere: 0
   Intersect Failed:1
   Point3d:(7.27921725290552, 9.921361924218475, 9.4356337532796)
   Bounds Centre:(2.794222605306934, 4.924908998991747, 5.365479443338677)
   Bounds Radius:7.851488707864601
TestBoundingSphere: 1
TestBoundingSphere: 2
   Intersect Failed:4
   Point3d:(6.276120730903036, 9.401577377786516, 6.807354475820597)
   Bounds Centre:(3.352516895032441, 4.148229279282045, 2.0173648466885634)
   Bounds Radius:7.686945185206554
TestBoundingSphere: 3
TestBoundingSphere: 4
TestBoundingSphere: 5
TestBoundingSphere: 6
   Intersect Failed:9
   Point3d:(8.038478163653613, 2.7162991107573955, 8.710219093378324)
   Bounds Centre:(3.4580070566391243, 3.7906526725175276, 2.309731231650905)
   Bounds Radius:7.94362612450896
TestBoundingSphere: 7
TestBoundingSphere: 8
TestBoundingSphere: 9
TestBoundingSphere: 10
TestBoundingSphere: 11
TestBoundingSphere: 12
   Intersect Failed:6
   Point3d:(8.348024864091503, 7.724240994419958, 7.910712126839192)
   Bounds Centre:(5.027143935497117, 4.472370837357689, 2.364337044370297)
   Bounds Radius:7.236379358196054
TestBoundingSphere: 13
   Intersect Failed:3
   Point3d:(8.504983098814863, 9.649212797422917, 7.797361182633625)
   Bounds Centre:(4.6838408648451075, 3.548377394137529, 4.154150790408732)
   Bounds Radius:8.06810402462829
TestBoundingSphere: 14
TestBoundingSphere: 15

[snip]


*** Code ***

import javax.media.j3d.*;
import javax.vecmath.*;

public class BoundTest
{

        public BoundTest()


        }

        public static void TestBoundingSphere()
        {
                BoundingSphere bounds = new BoundingSphere( new Point3d(0.0, 0.0, 0.0) 
,
0.0 );

                Point3d[] pointArray = new Point3d[10];

                for( int n = 0; n < pointArray.length; n++ )
                {
                        pointArray[n] = new Point3d(    java.lang.Math.random() * 10.0,
                                                                                       
 java.lang.Math.random() * 10.0,
                                                                                       
 java.lang.Math.random() * 10.0  );
                }

                bounds.combine( pointArray );

                Point3d center = new Point3d();
                bounds.getCenter( center );

                // attempt to translate the bounds to its center - this doesn't work
either...
                // Transform3D t3d = new Transform3D();
                // t3d.setTranslation( new Vector3d( center.x, center.y, center.z ) );
                // bounds.transform( t3d );

                for( int n = 0; n < pointArray.length; n++ )
                {
                        Point3d point = pointArray[n];

                        if( bounds.intersect( point ) == false )
                        {
                                System.out.println( "Intersect Failed:" + n );
                                System.out.println( "   Point3d:" + point );

                                System.out.println( "   Bounds Centre:" + center );
                                System.out.println( "   Bounds Radius:" +  
bounds.getRadius() );
                        }
                }
        }

        public static void main( String[] args )
        {
                for( int n = 0; n < 100; n++ )
                {
                        System.out.println( "TestBoundingSphere: " + n );
                        TestBoundingSphere();
                }
        }
}


=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to