12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- /**
- * @author Ben Houston / [email protected] / http://github.com/bhouston
- */
- ( function ( THREE ) {
- THREE.Plane = function ( normal, constant ) {
- // TODO: ensure that normal is of length 1 and if it isn't readjust both normal and constant?
- this.normal = normal || new THREE.Vector3();
- this.constant = constant || 0;
- };
- THREE.Plane.prototype.set = function ( normal, constant ) {
- // TODO: ensure that normal is of length 1 and if it isn't readjust both normal and constant?
- this.normal = normal;
- this.constant = constant;
- return this;
- };
- THREE.Plane.prototype.setComponents = function ( x, y, z, w ) {
- // TODO: ensure that normal is of length 1 and if it isn't readjust both normal and constant?
- this.normal.x = x;
- this.normal.y = y;
- this.normal.z = z;
- this.constant = w;
- return this;
- };
- THREE.Plane.prototype.copy = function ( plane ) {
- this.normal = plane.normal;
- this.constant = plane.constant;
- return this;
- };
- THREE.Plane.prototype.flip = function () {
- // Note: can also be flipped by inverting constant, but I like constant to stay positive generally.
- this.normal.negate();
- return this;
- };
- THREE.Plane.prototype.normalize = function () {
- // Note: will lead to a divide by zero if the plane is invalid.
- var inverseNormalLength = 1.0 / this.normal.length()
- this.normal.multipleByScalar( inverseNormalLength );
- this.constant *= inverseNormalLength;
- return this;
- };
- THREE.Plane.prototype.distanceToPoint = function ( point ) {
- return this.normal.dot( point ) + this.constant;
- };
- THREE.Plane.prototype.projectPoint = function ( point ) {
-
- return new THREE.Vector3().copy( point ).sub( this.orthoPoint( point ) );
- };
- THREE.Plane.prototype.orthoPoint = function ( point ) {
- var perpendicularMagnitude = this.distanceToPoint( point );
- return new THREE.Vector3().copy( this.normal ).multipleByScalar( perpendicularMagnitude );
- };
- THREE.Plane.prototype.intersectsLine = function ( startPoint, endPoint ) {
- // 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 );
- return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
- };
- THREE.Plane.prototype.coplanarPoint = function () {
-
- return this.projectPoint( new THREE.Vector3() );
- };
- }( THREE ) );
|