提交 3c5986bf 编写于 作者: B Ben Houston

incorporate Line3 into Plane.

上级 e08369e8
......@@ -115,12 +115,12 @@ THREE.extend( THREE.Plane.prototype, {
},
isIntersectionLine: function ( startPoint, endPoint ) {
isIntersectionLine: function ( line ) {
// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
var startSign = this.distanceToPoint( startPoint );
var endSign = this.distanceToPoint( endPoint );
var startSign = this.distanceToPoint( line.start );
var endSign = this.distanceToPoint( line.end );
return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
......@@ -130,20 +130,20 @@ THREE.extend( THREE.Plane.prototype, {
var v1 = new THREE.Vector3();
return function ( startPoint, endPoint, optionalTarget ) {
return function ( line, optionalTarget ) {
var result = optionalTarget || new THREE.Vector3();
var direction = v1.subVectors( endPoint, startPoint );
var direction = line.delta( v1 );
var denominator = this.normal.dot( direction );
if ( denominator == 0 ) {
// line is coplanar, return origin
if( this.distanceToPoint( startPoint ) == 0 ) {
if( this.distanceToPoint( line.start ) == 0 ) {
return result.copy( startPoint );
return result.copy( line.start );
}
......@@ -152,7 +152,7 @@ THREE.extend( THREE.Plane.prototype, {
}
var t = - ( startPoint.dot( this.normal ) + this.constant ) / denominator;
var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
if( t < 0 || t > 1 ) {
......@@ -160,7 +160,7 @@ THREE.extend( THREE.Plane.prototype, {
}
return result.copy( direction ).multiplyScalar( t ).add( startPoint );
return result.copy( direction ).multiplyScalar( t ).add( line.start );
};
......
......@@ -131,24 +131,25 @@ test( "distanceToSphere", function() {
test( "isInterestionLine/intersectLine", function() {
var a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 );
ok( a.isIntersectionLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ), "Passed!" );
ok( a.intersectLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
var l1 = new THREE.Line3( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) );
ok( a.isIntersectionLine( l1 ), "Passed!" );
ok( a.intersectLine( l1 ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), -3 );
ok( a.isIntersectionLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ), "Passed!" );
ok( a.intersectLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ).equals( new THREE.Vector3( 3, 0, 0 ) ), "Passed!" );
ok( a.isIntersectionLine( l1 ), "Passed!" );
ok( a.intersectLine( l1 ).equals( new THREE.Vector3( 3, 0, 0 ) ), "Passed!" );
a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), -11 );
ok( ! a.isIntersectionLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ), "Passed!" );
ok( a.intersectLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ) === undefined, "Passed!" );
ok( ! a.isIntersectionLine( l1 ), "Passed!" );
ok( a.intersectLine( l1 ) === undefined, "Passed!" );
a = new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 11 );
ok( ! a.isIntersectionLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ), "Passed!" );
ok( a.intersectLine( new THREE.Vector3( -10, 0, 0 ), new THREE.Vector3( 10, 0, 0 ) ) === undefined, "Passed!" );
ok( ! a.isIntersectionLine( l1 ), "Passed!" );
ok( a.intersectLine( l1 ) === undefined, "Passed!" );
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册