Three.js Source code Gaze (10) math/line3.js

Source: Internet
Author: User

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 also just started to learn, a lot of children are certainly not correct also forgive me.

The following code is the gaze of the Math/line3.js file in the Three.js source code file.

Many other 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 that is constructed by///.//////method of Use: 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 three-dimensional segment of the new coordinate value </returns>set:function (start, end) {this.start.copy (start); this.end.copy Return this;//a three-dimensional segment that returns a new coordinate value},/*///copy method is used to copy the starting point, end point, start,end coordinate value of a three-dimensional segment. and returns the new coordinate value of the three-dimensional segment .*////<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, assuming that there is no setting, the system itself creates a temporary Vector3 object *////< Summary>center</summary>///<param name = "Optionaltarget" type= "Vector3" >optionaltarget is an optional parameter, assuming no set , the system voluntarily 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, assuming that there is no setting, the system will voluntarily create a temporary Vector3 object return result.addvectors (This.start, This.end). Multiplyscalar (0.5);//returns the midpoint coordinate of the three-dimensional segment},/*///deThe LTA method is used to obtain the vector of the line segment and then transform it by applying various transformations through the matrix, zooming in and out, moving, etc.//Note:optionaltarget is an optional parameter, assuming that there is no setting, the system itself creates a temporary Vector3 object//Note: A vector is a directed line segment that is wrong, because the directed segment is fixed, that is, it cannot be panned, and the vector is capable of panning *////<summary>delta</summary>///<param name = " Optionaltarget "type=" Vector3 ">optionaltarget is an optional parameter, assuming there is no setting, the system voluntarily creates a temporary Vector3 object </param>///<returns Type= "Line3" > returns the vector </returns>delta:function of three-dimensional segments (optionaltarget) {var result = Optionaltarget | | new three. Vector3 ();//optionaltarget is an optional parameter, assuming that there is no setting, the system will voluntarily create a temporary Vector3 object return result.subvectors (This.end, This.start);// The vector},/*///distancesq method, which returns three-dimensional segments, is used to obtain the dot product (point multiplication, quantity product) of the current three-dimensional line segment starting point to the endpoint (read only).//Note: About dot product introduction Kauwiki Encyclopedia: 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 from the starting point of the current three-dimensional segment to the endpoint (read only). *////<summary>distanceto</ Summary>///&lT;returns type= "Number" > returns the distance from the starting point of the current three-dimensional segment to the endpoint (read only). </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 a random vector along the current three-dimensional segment direction, when T=0 returns the starting vector, when T=1 returns the end point vector. Note:optionaltarget is an optional parameter, assuming that there is no setting, the system itself proactively 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, assuming that there is no setting, the system itself creates a temporary Vector3 object </param>///<returns type= "Line3" > returns random vectors along the current three-dimensional segment direction Returns>at:function (t, optionaltarget) {var result = Optionaltarget | | new three. Vector3 ();//optionaltarget is an optional parameter, assuming that there is no setting, the system itself proactively creates a temporary Vector3 object return This.delta (Result). Multiplyscalar (t). Add ( This.start);//The random vector},/*///closestpointtopointparameter method that returns along the direction of the current three-dimensional segment will return a reference based on the point projection to the point on the line segment (that is, the position of the number points projection to the segment). Assuming that the parameter clamptoline is true, the return value will be between 0 and 1. *////<summary>closestpointtopointparameter</summary>///<param name = "point" type= "Vector3" > Value, Value Range 0-1&LT;/PARAM&GT;///<param name = "Clamptoline" type= "Boolean" > assuming that the parameter clamptoline is true, then the return value will be between 0 and 1. </param>///<returns type= "Number" > returns a reference based on the recent point projection to the point on the segment/returns>closestpointtopointparameter: 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 current point projection to the point on the segment (that is, the position of the reference points projection to the segment)}; (), the/*///closestpointtopoint method returns a vector based on the point projected onto the segment. Assuming that the parameter clamptoline is true, the returned vector is between the start and end points of the segment. Note:optionaltarget is an optional parameter, assuming that there is no setting, the system itself proactively creates a temporary Vector3 object *////<summary>closestpointtopoint</summary >///<param name = "point" type= "Vector3" > value, RANGE 0-1</param>///<param name = "Clamptoline" type= " Boolean > Assuming that the parameter clamptoline is true, then the returned vectorBetween the start and end points of the line segment. </param>///<param name = "Optionaltarget" type= "Vector3" >optionaltarget is an optional parameter, assuming no settings, The system voluntarily creates a temporary Vector3 object </param>///<returns type= "Number" > returns a vector based on the recent point projection onto the segment/returns> Closestpointtopoint:function (Point, Clamptoline, optionaltarget) {var t = this.closestpointtopointparameter (point, CL Amptoline); var result = Optionaltarget | | New three. Vector3 (); return This.delta (Result). Multiplyscalar (t). Add (This.start);//returns a vector based on the recent 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 controls the current line segment and the reference line, and is the starting and ending point control. Infer whether the segments are equal, return true or false.*////<summary>equals</summary>///<param name = "line" type= "Line3" > the segment to be controlled </param>///&Lt;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" > Return 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 the gaze of the Math/line3.js file in the Three.js source code file.

Many other updates in: Https://github.com/omni360/three.js.sourcecode/blob/master/Three.js

Three.js Source code Gaze (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.