Three. js source code annotation (10) Math/Line3.js, three. jsline3.js

Source: Internet
Author: User

Three. js source code annotation (10) Math/Line3.js, three. jsline3.js

Wuji (http://blog.csdn.net/omni360)

This article follows the "signature-non-commercial use-consistency" creation public agreement

Reprinted please keep this sentence: Wuji-this blog focuses on Agile development and mobile and IOT device research: data visualization, GOLANG, Html5, WEBGL, THREE. JS. Otherwise, the post from this blog will not be reprinted or reprinted. Thank you for your cooperation.


I also just started learning. Sorry for the errors in many places.

The following code is a comment on the Math/Line3.js file in the THREE. JS source code 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 * // Line3 object constructor. used to create a 3D line segment object. the functional functions of Line3 objects are implemented by using a function prototype object constructed. //// usage: var start = new Vector3 (, 0), end = new Vector3 (, 1); var line = new Line3 (start, end ); /// create a line segment whose start point is 0, 0, and end point is 1, 1. * //// <summary> Vector3 </summary> // <param name = "start" type = "Vector3"> start coordinate </param> /// <param name = "end" type = "Vector3"> end coordinate </p Aram> 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 functions provided by the Line3 object. **************************************** /THREE. line3.prototype = {constructor: THREE. the Line3, // constructor/* // set method is used to set the starting point, ending point, start, and end coordinate values of a three-dimensional line segment. returns the 3D line segment of the new coordinate value. * //// <summary> set </summary> /// <param name = "start" type = "Vector3"> start coordinate </param> /// <param name = "end" type = "Vector3"> end coordinate </param> // <returns type = "Line3"> return a new 3D line segment of the coordinate value </returns> set: function (start, end) {this. start. copy (start); this. end. copy (end); return this; // returns the 3D line segment of the new coordinate value}. The/* // copy method is used to copy the starting point, ending point, start, end coordinate value. returns the 3D line segment of the new coordinate value. * //// <summary> copy </summary> /// <param name = "line" type = "Line3"> 3D line segments </param> /// <returns type = "Line3"> returns the 3D line segment of the new coordinate value </returns> copy: function (line) {this. start. copy (line. start); this. end. copy (line. end); return this; // returns 3D line segment}, // The center method is used to obtain the midpoint of a line segment. /// NOTE: optionalTarget is an optional parameter, the system automatically creates a temporary Vector3 object * /// <summary> center </summary> /// <param name = "optionalTarget" type = "Vector3"> optionalTarget is an optional parameter., if this parameter is not set, the system automatically creates a temporary Vector3 object </param> // <returns type = "Line3"> returns the midpoint coordinates of a 3D line segment </returns> center: function (optionalTarget) {var result = optionalTarget | new THREE. vector3 (); // optionalTarget is an optional parameter. If no value is set, the system automatically creates a temporary Vector3 object ret. Urn result. addVectors (this. start, this. end ). multiplyScalar (0.5); // returns the coordinate of the midpoint of a 3D line segment}, and the // * // delta method is used to obtain the vector of a line segment. Then, various transformations are applied through the matrix to zoom in and out, mobile, etc. /// NOTE: optionalTarget is an optional parameter. If no parameter is set, the system automatically creates a temporary Vector3 object. // NOTE: the vector is a directed line segment, because the directed line segment is fixed, it cannot be translated, the vector is * /// <summary> delta </summary> /// <param name = "optionalTarget" type = "Vector3"> optionalTarget is an optional parameter, if no value is set, the system automatically creates a temporary Vector3 object </param> /// <returns type = "Line3"> returns the vector of the 3D line segment </r Eturns> delta: function (optionalTarget) {var result = optionalTarget | new THREE. vector3 (); // optionalTarget is an optional parameter. If no value is set, the system automatically creates a temporary Vector3 object return result. subVectors (this. end, this. start); // returns the vector of a 3D line segment},/* // The distanceSq method is used to obtain the dot product (DOT multiplication, quantity product) from the start point to the endpoint of the current 3D line segment (read-only ). /// NOTE: For more information about Dot Product, see Wikipedia: vertex <summary> distanceSq </summary> /// <returns type = "Vector"> returns the current 3D line segment. Point product from the start point to the endpoint (point multiplication, number product) </returns> distanceSq: function () {return this. start. distanceToSquared (this. end); // returns the Point product (point multiplication, quantity product) from the start point to the endpoint of the current 3D line segment )}, /* // The distanceTo method returns the distance from the start point of the current 3D line segment to the endpoint (read-only ). * //// <summary> distanceTo </summary> // <returns type = "Number"> returns the distance from the starting point of the current 3D line segment to the endpoint (read-only ). </returns> distance: function () {return this. start. distanceTo (this. end); // returns the distance from the start point to the endpoint of the current 3D line segment (read-only ).}, /* // The at method returns any vector along the direction of the current 3D line segment. If t = 0, the start vector is returned. If t = 1, the end point is returned. Vector. /// NOTE: optionalTarget is an optional parameter, the system automatically creates a temporary Vector3 object * /// <summary> at </summary> /// <param name = "t" type = "Number"> value, value Range: 0-1 </param> // <param name = "optionalTarget" type = "Vector3"> optionalTarget is an optional parameter. If no value is set, the system automatically creates a temporary Vector3 object </param> // <returns type = "Line3"> returns any vector along the current 3D line segment/returns> at: function (t, optionalTarget) {var result = optionalTarget | new THREE. vector3 (); // optionalTarget is an optional parameter. The system automatically creates a temporary Vector3 object return this. delta (result ). multiplyScalar (t ). add (this. start); // returns any vector along the direction of the current 3D line segment }, /* // The closestPointToPointParameter method returns a parameter (that is, the parameter point is projected to the position of the Line Segment) based on the point projection to the point on the line segment ). If the clampToLine parameter is true, the returned value is 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, the return value is between 0 and 1. </Param> /// <returns type = "Number"> returns a parameter/returns> closestPointToPointParameter: function () that is projected from the nearest vertex to the vertex on the line segment () {var startP = new THREE. vector3 (); var startEnd = new THREE. vector3 (); return function (point, clampToLine) {startP. subVectors (point, this. start); startEnd. subVectors (this. end, this. start); var startEnd2 = startEnd. dot (startEnd); var startEnd_startP = startEnd. dot (startP); var t = startEnd_st ArtP/startEnd2; if (clampToLine) {t = THREE. math. clamp (t, 0, 1); // call THREE. math. the clamp () method ensures that the tvalue is between 0 and 1 .} return t; // return a parameter (that is, the position where the parameter point is projected to the line segment) that is projected to the point on the Line Segment Based on the closest point )};}(), /* // The closestPointToPoint method returns a vector projected to a line segment based on a vertex. If the parameter clampToLine is true, the starting point and ending point of the returned vector online segment are. /// NOTE: optionalTarget is an optional parameter, the system automatically creates a temporary Vector3 object * // <summary> closestPointToPoint </summary> // <param name = "point" type = "Vector3"> value, value Range: 0-1 </param> // <param name = "clampToLine" type = "Boolean"> If the clampToLine parameter is true, then, the starting point and ending point of the returned vector online segment are. </Param> /// <param name = "optionalTarget" type = "Vector3"> optionalTarget is an optional parameter, the system automatically creates a temporary Vector3 object </param> // <returns type = "Number"> returns a vector/returns> closestPointToPoint Based on the closest point projected on the line segment: function (point, 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 projected to a line segment based on the closest vertex.}, // * // returns the start point of a line segment using the applyMatrix4 method, and applies matrix transformation to the end point. achieve the purpose of rotation, scaling, and movement. * //// <summary> applyMatrix4 </summary> /// <param name = "m" type = "Matrix4"> affine matrix </param> /// <returns type = "Line3"> returns the 3D line segment of the new coordinate value </returns> applyMatrix4: function (matrix) {this. start. applyMatrix4 (matrix); this. end. applyMatrix4 (matrix); return this; // returns the 3D line segment of the new coordinate value}. The/* // equals method compares the current line segment with the line parameter, it is the comparison between the start point and the end point. returns true or false if the line segments are equal. * //// <summary> equals </summary> // <param name = "line" type = "Line3"> line segment for comparison </param> /// <returns type = "Boolean"> return true or false </returns> equals: function (line) {return line. start. equals (this. start) & line. end. equals (this. end); // return true or false},/* clone method // clone method to clone a 3D line segment object. * //// <summary> clone </summary> /// <returns type = "Line3"> returns a 3D line segment object. </returns> clone: function () {return new THREE. line3 (). copy (this); // returns a 3D line segment object }};


Wuji (http://blog.csdn.net/omni360)

This article follows the "signature-non-commercial use-consistency" creation public agreement

Reprinted please keep this sentence: Wuji-this blog focuses on Agile development and mobile and IOT device research: data visualization, GOLANG, Html5, WEBGL, THREE. JS. Otherwise, the post from this blog will not be reprinted or reprinted. Thank you for your cooperation.


The following code is a comment on the Math/Line3.js file in the THREE. JS source code file.

More updates in: https://github.com/omni360/three.js.sourcecode/blob/master/Three.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.