Commercial Territory (http://blog.csdn.net/omni360/)
This article follows "Attribution-non-commercial use-consistent" authoring public agreement
Reprint Please keep this sentence: Business Domain-this blog focuses on Agile development and mobile and IoT device research: Data visualization, Golang, HTML5, WEBGL, three. JS, Otherwise, from this blog article refused to reprint or reprint, thank you for your cooperation.
I was just beginning to learn, a lot of things are definitely wrong and please forgive me.
The following code is a comment for the math/plane.js file in the three.js source file.
More updates in: https://github.com/omni360/three.js.sourcecode/blob/master/Three.js
file:src/math/plane.js/** * @author The constructor of the Bhouston/http://exocortex.com *//*///plane object. Used to create a normal vector in three-dimensional space as normal, The distance from the origin to the plane is an infinitely extended two-dimensional planar object of constant. The functions of the plane object are implemented using the function prototype object defined by///.//////usage: var normal = new Vector3 (0,0,0), constant = 5.5; var Plane = new Plane (normal,constant); Create a normal vector is a two-dimensional plane where the distance from the 0,0,0 origin to the plane is 5.5. *////<summary>plane</summary >///<param name = "normal" type= "Vector3" > Plane normal vector </param>///<param name = "Constant" type= "number" >number the distance from the origin of the two-dimensional plane </param>three. Plane = function (normal, constant) {This.normal = (normal!== undefined)? normal:new three. Vector3 (1, 0, 0);//assignment or initialization of normalthis.constant = (constant!== undefined)? constant:0;//Assignment or initialization constant};/******************************************** The following are the function functions provided by the plane object. ***************** /three. Plane.prototype = {Constructor:three. The plane,//constructor returns a reference to the Plane function that created this object/*///set method is used to reset the normal vector of the two-dimensional plane to normal, the distance from the origin to the plane constant, and returns the new two-dimensional plane .*////<summary> Set</summary>///<paramname = "normal" type= "Vector3" > Plane normal vector </param>///<param name = "Constant" type= "number" > Number two-dimensional distance from Origin </param>///<returns type= "Plane" > Returns a new two-dimensional plane </returns>set:function (normal, Constant) {this.normal.copy (normal); this.constant = Constant;return this;//Returns a new two-dimensional planar},/*///setcomponents method for use with x, Y, Z , the W component re-sets the normal vector of the two-dimensional plane normal, the distance from the origin to the plane constant, and returns the new two-dimensional plane .*////<summary>setcomponents</summary>///< param name = "normal" type= "Vector3" > Plane normal vector </param>///<param name = "x" type= "number" > plane normal vector x coordinate </ Param>///<param name = "Y" type= "number" > plane normal vector y coordinate </param>///<param name = "Z" type= "number" > Plane normal vector z coordinate </param>///<param name = "W" type= "number" >number the distance from the origin of the two-dimensional plane w</param>///<returns type= "Plane" > returns the new two-dimensional plane </returns>setcomponents:function (x, Y, Z, W) {This.normal.set (x, y, z); this.constant = W;re Turn this;//returns a new two-dimensional planar},/*///setfromnormalandcoplanarpoint method for re-setting the normal vector N of a two-dimensional plane by the parameter normal (plane normal vector) and the parameter point (coplanar)Ormal, the distance from the origin to the plane is constant, and the new two-dimensional plane is returned. *////<summary>setfromnormalandcoplanarpoint</summary>///<param name = "normal" type= "Vector3" > Plane normal vector </param>///<param name = "point" type= "Vector3" > Coplanar points </param >///<returns type= "Plane" > Return to the new two-dimensional plane </returns>setfromnormalandcoplanarpoint:function (normal, point) {this.normal.copy (normal);//The following Point.dot () method only receives This.normal, does not receive normal,this.normal is normalized, is the unit vector this.constant =- Point.dot (this.normal);//Must be this.normal, not normal, as This.normal is Normalizedreturn this;//and returns a new two-dimensional plane},/*///set The Fromcoplanarpoints method is used to re-set the normal vector of the two-dimensional plane by the coplanar point A,b,c Normal, the distance from the origin to the plane constant, and returns the new two-dimensional plane.//NOTE: The Setfromcoplanarpoints method accepts 3 point a,b,c that need to be passed in a counterclockwise direction to determine the direction of discovery. *////<summary>setfromcoplanarpoints</ Summary>///<param name = "a" type= "Vector3" > coplanar point a</param>///<param name = "B" type= "Vector3" > Coplanar point B</param>///<param name = "C" type= "Vector3" > Coplanar point c</param>///<returns type= "Plane" > Returns a new two-dimensional planar </returns>setfromcoplanarpoints:function () {var v1 = new three. Vector3 (); var v2 = new three. Vector3 (); return function (A, B, c) {var normal = V1.subvectors (c, B). Cross (V2.subvectors (A, b)). normalize ();//Get First The difference of the vector c,b, the cross product of the vector A/b difference is obtained by the Cross method (the crossover product is perpendicular to the plane of the vector, A, b), and then the unit vector is obtained in the call normalize () method.//Q:should An error being thrown if normal is Zero (e.g. degenerate plane)?//note: If the normal vector is 0, an invalid planar object is generated. This.setfromnormalandcoplanarpoint (normal, a); The Setfromnormalandcoplanarpoint method is used to re-set the normal vector of the two-dimensional plane through the parameter normal (plane normal vector) and the parameter point (coplanar points), the distance constant from the origin to the plane, and returns a new two-dimensional plane. Return this;//returns a new two-dimensional plane}; (), the/*///copy method is used to copy the normal vector of the two-dimensional plane, the distance constant value from the origin to the plane. Returns the new two-dimensional plane///todo:copy method and the Clone method are different?*////<summary> Copy</summary>///<param name = "Plane" type= "Plane" > two-dimensional plane </param>///<returns type= "Plane" > Returns the new two-dimensional planar </returns>copy:function (plane) {this.normal.copy (plane.normal); this.constant = plane.constant; Return this;//Returns a new two-dimensional planar},/*///normalize method that normalizes the normal vector and adjusts the value of the constant constant (to get the unit plane).*////<summary>normalize</summary>///<returns type= "Plane" > return normalized two-dimensional plane (get unit plane) </returns> Normalize:function () {//Note:will leads to a divide by zero if the plane is invalid.//Note: Note If the plane is invalid the divisor is 0 error. var INV Ersenormallength = 1.0/this.normal.length (); This.normal.multiplyScalar (inversenormallength); This.constant *= Inversenormallength;return this;//Returns a normalized two-dimensional plane (obtains the unit plane)},/*///negate method is used to flip the normal, get the back of the current plane, *////<summary>negate </summary>///<returns type= "Plane" > returns the back of the current plane </returns>negate:function () {this.constant *=-1; This.normal.negate ();//Flip Normal, Vector3.negate method returns a positive number if the (x, y, z) coordinate value of the current three-dimensional vector is negative. When the current three-dimensional vector (x, y, z) coordinate value is positive, a negative number is returned. Return this;//returns the back of the current plane},/*///distancetopoint method is used to obtain the minimum length of a point to plane two-dimensional planar object surface in three-dimensional space .*////<summary> Distancetopoint</summary>///<param name = "point" type= "Vector3" > three-dimensional points coordinates of VECTOR3 in a three-dimensional space </param>// /<returns type= "Number" > returns the minimum length of a point to plane two-dimensional planar object surface within a three-dimensional space. </returns>distancetopoint:function (point) {RETUrn This.normal.dot (point) + this.constant;//returns the minimum length of the surface of a two-dimensional planar object within a three-dimensional space},/*/// The Distancetopoint method is used to obtain the minimum length of a sphere surface in a plane two-dimensional plane object to three-dimensional space. () *////<summary>distancetopoint</summary>///<param name = "Sphere" type= "sphere" > A sphere sphere object in a three-dimensional space </param>///<returns type= "number" > returns the minimum length of a sphere's surface within a three-dimensional space plane a two-dimensional planar object. </ Returns>distancetosphere:function (Sphere) {return this.distancetopoint (sphere.center)-sphere.radius;// Returns the minimum length of a sphere's surface within a three-dimensional space plane two-dimensional plane object to three-dimensional space},/*///projectpoint method returns a point in three-dimensional space to the projection of the current plane. The projection on the point-to-face is equal to the perpendicular from the parameter points to the plane, So draw a line from perpendicular to the point perpendicular to the plane. *////<summary>projectpoint</summary>///<param name = "point" type= "Vector3" > Vector3 three-dimensional vector </param>///<param name = "Optionaltarget" type= "Vector3" > Optional parameters, receive return results </param>///< Returns type= "Number" > Return to Plane projection </returns>projectpoint:function (point, Optionaltarget) {return This.orthopoint (Point, Optionaltarget). Sub (point). Negate ()//Call the Orthopoint () method, minus point, and return the result of the inverse},/*/// The Orthopoint method returns a current two-dimensionalThe plane object normal vector is in the same direction as the vector (perpendicular) of the parameter point to the plane distance. If the Optionaltarget parameter is set, the result is saved in Optionaltarget .*////<summary> Orthopoint</summary>///<param name = "point" type= "Vector3" >vector3 three-dimensional vector </param>///<param name = "Optionaltarget" type= "Vector3" > Optional parameters, receive return results </param>///<returns type= "Vector3" > Returns a vector (perpendicular) that is the same direction as the normal vector of the current two-dimensional plane object, equal to the distance from the parameter point to the plane. </returns>orthopoint:function (point, Optionaltarget) {var Perpendicularmagnitude = This.distancetopoint (point);//Gets the distance from the plane to the parameter point and assigns the value to prependicularmagnitudevar result = Optionaltarget | | New three. Vector3 ();//Life variable Resault, used to store the result return result.copy (this.normal). Multiplyscalar (perpendicularmagnitude);// Call the Multiplyscalar (Perpendicularmagnitude) method to multiply the normal vector of the current two-dimensional plane by x, Y, z, respectively, by the distance from the plane to the parameter point. Finally, the calculation results are returned.},/*/// The Isintersectionline method gets whether the current two-dimensional plane intersects the parameter line and returns TRUE or false*////<summary>isintersectionline</summary>/// <param name = "line" type= "Line3" > lines in three-dimensional space line3</param>///<returns type= "Boolean" > returns TRUE or False </rEturns>isintersectionline:function (line) {//Note:this tests if a line intersects the plane, not whether it (or it S end-points) is coplanar with it.//note:isintersectionline () is the test line and polygon intersection, not mistakenly thought line and Polygon is coplanar var startsign = This.distancetopoint (Line.start); var endsign = This.distancetopoint (line.end); return (Startsign < 0 && End Sign > 0) | | (Endsign < 0 && startsign > 0);//returns TRUE or False},/*///intersectline method gets the intersection of the current two-dimensional plane and the parameter line. If the and parameter line does not intersect return undefined, if the lines and the current two-dimensional planar coplanar return the starting point of the line. *////<summary>isintersectionline</summary>///<param Name = "line" type= "Line3" > three-dimensional space in Line3</param>///<param name = "Optionaltarget" type= "Vector3" > Optional parameters, Receives the returned result </param>///<returns type= "Boolean" > returns the intersection of the current two-dimensional plane and the parameter line, if it does not intersect with the parameter line or other unknown return undefined, If the line and the current two-dimensional planar coplanar return the starting point of the line. </returns>intersectline:function () {var v1 = new three. Vector3 (); return function (line, optionaltarget) {var result = Optionaltarget | | new three. Vector3 (); var direction = LiNe.delta (v1); var denominator = This.normal.dot (direction); if (denominator = = 0) {//Line is coplanar, return origin/ /If the line and the current two-dimensional planar coplanar return line start if (this.distancetopoint (line.start) = = 0) {return result.copy (Line.start);} Unsure if the correct method to handle this case.//if other unknowns return undefinedreturn undefined;} var t =-(Line.start.dot (this.normal) + this.constant)/denominator;if (T < 0 | | T > 1) {return undefined;// If the parameter line does not intersect return Undefined}return result.copy (direction). Multiplyscalar (t). Add (Line.start);//returns the intersection of the current two-dimensional plane and the parameter line} ;} (), the/*///coplanarpoint method obtains the normal vector of the current two-dimensional plane to the current two-dimensional planar projection (perpendicular, the coplanar point of the current plane).///todo: It's not clear here, there's time to figure out, high school geometry is almost forgotten, It's a dead-over. However, you know that you called the. *////<summary>coplanarpoint</summary>///<param name = "Optionaltarget" type= "when you apply the transform below. Vector3 "> optional parameter, receives the returned result </param>///<returns type=" Boolean "> returns the Coplanar point. </returns>coplanarpoint: function (optionaltarget) {var result = Optionaltarget | | new three. Vector3 (); return Result.copy (this.normal). MultiplYscalar (-this.constant);//return Coplanar point},/*///applymatrix4 method by passing the matrix (rotation, scaling, moving transformation matrix) to the current plane two-dimensional plane object normal vector normal and, apply the transformation. *////<summary>applymatrix4</summary>///<param name = "Matrix" type= "Matrix4" > (rotation, scaling, moving and other transformation matrices </ Param>///<param name = "Optionalnormalmatrix" type= "Matrix3" > Optional parameters, if set it will apply to normal (rotation, scaling, moving and other transformation matrices </param >///<returns type= "Boolean" > returns the transformed two-dimensional plane. </returns>applymatrix4:function () {var v1 = new three. Vector3 (); var v2 = new three. Vector3 (); var m1 = new three. Matrix3 (); return function (Matrix, Optionalnormalmatrix) {//Compute new normal based on theory here://Http://www.songh O.ca/opengl/gl_normaltransform.htmlvar Normalmatrix = Optionalnormalmatrix | | M1.getnormalmatrix (Matrix), var newnormal = v1.copy (this.normal). ApplyMatrix3 (Normalmatrix); var newcoplanarpoint = th Is.coplanarpoint (v2);//Gain coplanar point newcoplanarpoint.applymatrix4 (Matrix); This.setfromnormalandcoplanarpoint ( Newnormal, Newcoplanarpoint);//setfromnormalandcoplanarpoint method is used toParameters normal (plane normal vector) and parameter point (coplanar points) re-set the normal vector of the two-dimensional plane normal, the distance from the origin to the plane is constant, and the new two-dimensional plane is returned. Return this;//returns the transformed two-dimensional plane}; (), the/*///translate method is used to move the position of the current two-dimensional plane through the parameter offset. *////<summary>translate</summary>///<param name = " Offset "type=" Vector3 "> Offset </param>///<returns type=" Boolean "> Returns a new two-dimensional planar </returns>translate: function (offset) {this.constant = This.constant-offset.dot (this.normal); return this;//returns a new two-dimensional planar},/*///equals method to obtain the parameter The number plane (a plane two-dimensional plane) is exactly equal to the current two-dimensional plane, that is, the normal vector normal and the radius are equal. *////<summary>equals</summary>///<param name = "Plane" type= "Plane" > a Plane two-dimensional plane </param>///<returns type= "Boolean" > returns TRUE or false</returns> Equals:function (plane) {return plane.normal.equals (this.normal) && (plane.constant = = this.constant);//Return T Rue or False},/*clone method///clone method clones a two-dimensional planar object. *////<summary>clone</summary>///<returns type= "Plane" > Returns a two-dimensional planar object </returns>clone:function () {return new three. Plane (). copy (this);//return evaporating faceLike}};
Commercial Territory (http://blog.csdn.net/omni360/)
This article follows "Attribution-non-commercial use-consistent" authoring public agreement
Reprint Please keep this sentence: Business Domain-this blog focuses on Agile development and mobile and IoT device research: Data visualization, Golang, HTML5, WEBGL, three. JS, Otherwise, from this blog article refused to reprint or reprint, thank you for your cooperation.
The following code is a comment for the math/plane.js file in the three.js source file.
More updates in: https://github.com/omni360/three.js.sourcecode/blob/master/Three.js
Three.js Source Note (15) Math/plane.js