Three.js Source Note (10) math/line3.js

Source: Internet
Author: User
Tags function prototype

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/line3.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/line3.js/** * @author bhouston/http://exocortex.com *//*/// The constructor for the Line3 object. Used to create a three-dimensional segment object. The function function of the Line3 object is implemented using the function prototype object defined by///.//////usage: var start = new Vector3 (0,0,0), end = new Vector3 ( 1,1,1); var line = new Line3 (start,end);////Create a starting point start for 0,0,0 and end point to 1,1,1 segment. *////<summary>vector3</summary>/ <param name = "Start" type= "Vector3" > start point coordinates </param>///<param name = "End" type= "Vector3" > end point coordinates </ Param>three. Line3 = function (start, end) {This.start = (start!== undefined)? start:new three. Vector3 (); this.end = (end!== undefined)? End:new three. Vector3 ();};/ The following are the function functions provided by the Line3 object. ****************************************/three. Line3.prototype = {Constructor:three. The line3,//constructor/*///set method is used to set the starting point, end point, and start,end coordinate value of the three-dimensional segment from the new. and returns a three-dimensional segment of the newly-coordinate value. *////<summary>set</summary>/// <param name = "Start" type= "Vector3" > start point coordinates </param>///<param name = "End" type= "Vector3" > end point coordinates </ Param>///<reTurns type= "Line3" > returns the new coordinate value of the three-dimensional segment </returns>set:function (start, end) {this.start.copy (start); This.end.copy ( End) return this;//a three-dimensional segment},/*///copy method that returns a new coordinate value to copy the starting point, end point, and start,end coordinate value of a three-dimensional segment. and returns a three-dimensional segment of the new coordinate value. *////<summary>copy </summary>///<param name = "line" type= "Line3" > three-dimensional segment </param>///<returns type= "Line3" > Returns the three-dimensional segment of the new coordinate value </returns>copy:function (line) {this.start.copy (Line.start); this.end.copy (line.end); return this ;//Returns the new coordinate value of the three-dimensional segment},/*///center method is used to obtain the midpoint of the segment.//Note:optionaltarget is an optional parameter, and if not set, a temporary Vector3 object is created automatically *////<summary >center</summary>///<param name = "Optionaltarget" type= "Vector3" >optionaltarget is an optional parameter, if not set, The system automatically creates a temporary Vector3 object </param>///<returns type= "Line3" > returns the midpoint coordinate of the three-dimensional segment </returns>center:function ( Optionaltarget) {var result = Optionaltarget | | new three. Vector3 ();//optionaltarget is an optional parameter, if not set, the system automatically creates a temporary Vector3 object return result.addvectors (This.start, This.end). Multiplyscalar (0.5);//returns the midpoint coordinate of three-dimensional segment},/*///delta method is used to obtainThe vector of the line segment, and then the various transformations are applied through the matrix, zooming in and out, moving and so on.//Note:optionaltarget is an optional parameter, and if not set, the system automatically creates a temporary Vector3 object//Note: The vector is the line segment that is wrong, Because the directed segment is fixed, that is, it cannot be panned, and the vector can be panned *////<summary>delta</summary>///<param name = "Optionaltarget" type= " Vector3 ">optionaltarget is an optional parameter, if not set, the system automatically creates a temporary Vector3 object </param>///<returns type=" Line3 "> Returns a vector of three-dimensional segments </returns>delta:function (optionaltarget) {var result = Optionaltarget | | new three. Vector3 ();//optionaltarget is an optional parameter, if not set, the system automatically creates a temporary Vector3 object return result.subvectors (This.end, This.start);// The vector},/*///distancesq method that returns the three-dimensional segment is used to obtain the dot product (point multiplication, quantity product) (read-only) of the current three-dimensional segment starting point to the endpoint.//Note: Introduction to dot Product reference Wikipedia: Http://zh.wikipedia.org/wiki /%e6%95%b0%e9%87%8f%e7%a7%af*////<summary>distancesq</summary>///<returns type= "Vector" > Returns the dot product (point multiplication, quantity product) of the current three-dimensional segment starting point to the endpoint </returns>distancesq:function () {return this.start.distanceToSquared (this.end);// Returns the dot product (point multiplication, quantity product) of the current three-dimensional segment starting point to the endpoint},/*///distanceto method returns the distance (read-only) from the starting point of the current three-dimensional segment to the endpoint. *////<summary>distanceto</summary >///<returns type= "Number > returns the distance (read-only) from the starting point of the current three-dimensional segment to the endpoint. </returns>distance:function () {return this.start.distanceTo (this.end);// Returns the distance from the starting point of the current three-dimensional segment to the endpoint (read-only). The},/*///at method returns any vector along the current three-dimensional segment direction, when T=0 returns the start vector, when T=1 returns the end point vector.///Note:optionaltarget is an optional parameter, if not set, The system automatically creates a temporary Vector3 object *////<summary>at</summary>///<param name = "T" type= "number" > Value range 0-1</ Param>///<param name = "Optionaltarget" type= "Vector3" >optionaltarget is an optional parameter, if not set, the system automatically creates a temporary Vector3 object < /param>///<returns type= "Line3" > returns any vector along the current three-dimensional segment direction/returns>at:function (T, optionaltarget) {var result = Optionaltarget | | New three. Vector3 ();//optionaltarget is an optional parameter, and if not set, the system automatically creates a temporary Vector3 object return This.delta (Result). Multiplyscalar (t). Add ( This.start);//returns the arbitrary vector},/*///closestpointtopointparameter method along the current three-dimensional segment direction returns a parameter based on the point projection to the point on the segment (that is, the position of the parameter points projected to the segment). If the parameter clamptoline is true, then the return value will be between 0 and 1. *////<summary>closestpointtopointparameter</summary>///<param name = "point" type= "Vector3" > Value, Value range 0-1</param>///<param name = "clAmptoline "Type=" Boolean > if the parameter clamptoline is true, then the return value will be between 0 and 1. </param>///<returns type= "Number" > returns a parameter/returns>closestpointtopointparameter based on the nearest point projection to the point on the segment: function () {var STARTP = new three. Vector3 (); var startend = new three. Vector3 (); return function (point, Clamptoline) {startp.subvectors (point, This.start); Startend.subvectors (This.end, t His.start); var startEnd2 = Startend.dot (startend); var startend_startp = Startend.dot (STARTP); var t = STARTEND_STARTP /startend2;if (clamptoline) {t = three. Math.clamp (t, 0, 1); Call the THREE.Math.clamp () method to guarantee that the T value is between 0-1.} Return t;//Returns a parameter based on the nearest point projection to the point on the segment (that is, the position of the parameter, "dot projection" to the Segment)};} (), the/*///closestpointtopoint method returns a vector based on the point projected onto the segment. If the parameter clamptoline is true, the returned vector is between the starting and ending points of the segment. Note:optionaltarget is an optional parameter, and if not set, the system automatically creates a temporary Vector3 object *////<summary>closestpointtopoint</summary>/ <param name = "point" type= "Vector3" > value, RANGE 0-1</param>///<param name = "Clamptoline" type= "Boolean" > If the parameter clamptoline is true, the returned vector is between the starting and ending points of the segment. </param>///<param name = "Optionaltarget" type= "Vector3" >optionaltarget is an optional parameter, if not set, the system automatically creates a temporary Vector3 object </param >///<returns type= "Number" > Returns a vector/returns>closestpointtopoint:function (point, which is projected onto a segment based on the nearest dot,  Clamptoline, optionaltarget) {var t = this.closestpointtopointparameter (point, Clamptoline); var result = Optionaltarget || New three. Vector3 (); return This.delta (Result). Multiplyscalar (t). Add (This.start);//returns a vector based on the nearest point projection onto the line segment},/*/// The ApplyMatrix4 method applies a matrix transformation to the start point and end point of the line segment. achieve rotation, scaling, and movement purposes. *////<summary>applymatrix4</summary>///<param Name = "M" type= "Matrix4" > Affine matrix </param>///<returns type= "Line3" > Return three-dimensional segment </returns>applymatrix4 of new coordinate values: function (matrix) {this.start.applyMatrix4 (matrix); this.end.applyMatrix4 (matrix); return this;//returns a three-dimensional segment of the new coordinate value},/*/// The Equals method compares the current segment to the parameter line, and the segment comparison is the start and end point comparison. Determines whether the segments are equal, returns TRUE or false.*////<summary>equals</summary>///<param name = "line" type= "Line3" > Lines for comparison </param>///<returns type= "Boolean"; returns TRUE or False</returns>equals:function (line) {return line.start.equals (This.start) && Line.end.equals (this.end);//returns True or False},/*clone method///clone method clones a three-dimensional segment object. *////<summary>clone</summary >///<returns type= "Line3" > returns the three-dimensional segment object </returns>clone:function () {return new three. Line3 (). copy (this);//return three-dimensional segment object}};


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/line3.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 (10) math/line3.js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.