As we are on the subject of Bounds here is a strange problem that I ran into
a while back. It could be a bug in the BoundingSphere combine method.

Basically, if you use the "combine" method to generate a BoundingSphere from
a series of points, and then check that the generated sphere encloses those
points, the "intersect" method will fail on _some_ of the points!

Maybe, I have misunderstood how this is supposed to work... but I ended up
rolling my own "combine" method that would generate a BoundingSphere from an
array of points that DID enclose all of the points in the array.

I have attached a simple test function. I also checked whether BoundingBox
has this problem, and it does _not_.

Any explanations anyone?

Good luck,

Daniel Selman
Tornado Labs Ltd.

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



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Rajesh
Gupta
Sent: 13 April 1999 08:03
To: [EMAIL PROTECTED]; Java3d
Subject: Re: [java3d] Bounds computing


Hi Michael,

You can construct a BoundingBox object from a BoundingSphere. One of the
BoundingBox constructors takes a Bounds object where you can pass in the
BoundingSphere.
If you want to implement a method, it would look like

BoundingBox getBoxBounds()
{
    return new BoundingBox( getBounds());
}

Though you may not like to do a new everytime, especially if you are calling
it lots of times.

Hope it helps,

Regards,
Rajesh Gupta

----- Original Message -----
From: Michael Wilimsky <[EMAIL PROTECTED]>
To: Java3d <[EMAIL PROTECTED]>
Sent: Tuesday, April 13, 1999 12:30 PM
Subject: Re: [java3d] Bounds computing


thanx for the info rajesh...

do You know how i could get a boundingbox in return for my getBoundsMethod?
i
don�t want a
cube as Bounding Object for every scenegraph object....

the problem is, that i can�t override the final getBounds() method....

poohh... what do You think?

michy

Rajesh Gupta wrote:

> Hi Michael,
>
> Don't know about J3D1.1.1, but till 1.1, even the BoundingBox was
internally
> stored as a BoundingSphere. And it is documented, where exactly, I will
have
> to look up.
> That probably explains your observation.
>
> Regards,
> Rajesh Gupta
>
> ----- Original Message -----
> From: Michael Wilimsky <[EMAIL PROTECTED]>
> To: Java3d <[EMAIL PROTECTED]>
> Sent: Tuesday, April 13, 1999 12:09 PM
> Subject: [java3d] Bounds computing
>
> > I need help!
> >
> > everytime I call the getBounds()-method of my SceneGraphObjects i get a
> > BoundingSphere-Object...
> > even if i set the Bounds as a BoundingBox Object :
> >
> > setBounds(new BoundingBox(new Point3d(x1, y1, z1), new Point3d(x2, y2,
> > z2)))
> >
> > but i would rather like to get a BoundingBox...
> >
> > what do i have to do ?
> >
> > michy
> >
> > =====================================================================
> > To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
> > Java 3D Home Page: http://java.sun.com/products/java-media/3D/
> >

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

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

/*
//*****************************************************************************
/*
*	@(#) BoundTest.java
*
*	Project:	(none)
*	Client:		(none) Freely distributable
*
*	Copyright (c) 1999 Tornado Labs, Ltd. 
*	All Rights Reserved.
*
*	http://www.tornadolabs.com
*
*	@author Daniel Selman ([EMAIL PROTECTED])
*/
//*****************************************************************************

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 );
				
		// attempt to translate the bounds to its center - this doesn't work either
		Point3d center = new Point3d();
		bounds.getCenter( center );

		// 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 TestBoundingBox()
	{
		BoundingBox bounds = new BoundingBox( new Point3d(0.0, 0.0, 0.0), new Point3d(0.0, 0.0, 0.0) );
				
		Point3d[] pointArray = new Point3d[100];
		
		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 );
				
		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 );
			}
		}
	}


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

Reply via email to