Browse Source

Merge remote-tracking branch 'Fox32/dev' into dev

Mr.doob 12 years ago
parent
commit
f606c5a7e1
2 changed files with 17 additions and 0 deletions
  1. 8 0
      src/math/Sphere.js
  2. 9 0
      test/unit/math/Sphere.js

+ 8 - 0
src/math/Sphere.js

@@ -67,6 +67,14 @@ THREE.Sphere.prototype = {
 
 	},
 
+	isIntersectionSphere: function( sphere ) {
+
+		var radiusSum = this.radius + sphere.radius;
+
+		return ( sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum ) );
+		
+	},
+
 	clampPoint: function ( point, optionalTarget ) {
 
 		var deltaLengthSq = this.center.distanceToSquared( point );

+ 9 - 0
test/unit/math/Sphere.js

@@ -60,6 +60,15 @@ test( "distanceToPoint", function() {
 	ok( a.distanceToPoint( one3 ) === -1, "Passed!" );
 });
 
+test( "isIntersectionSphere", function() {
+	var a = new THREE.Sphere( one3, 1 );
+	var b = new THREE.Sphere( zero3, 1 );
+	var c = new THREE.Sphere( zero3, 0.25 );
+
+	ok( a.isIntersectionSphere( b ) , "Passed!" );
+	ok( ! a.isIntersectionSphere( c ) , "Passed!" );
+});
+
 test( "clampPoint", function() {
 	var a = new THREE.Sphere( one3, 1 );