Three.js Source Note (17) Math/math.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 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/math.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/math.js/** * @author alteredq/http://alteredqualia.com/* @author mrdoob/http://mrdoob.com/*//*///Ma The constructor of the th object. Contains some common mathematical methods. The//////generateuuid () method is used to generate a 36-bit UUID Universal Unique identifier (universally unique Identifier).///clamp () method is used to limit the value of x between A and B, and if X is less than a, returns a. If x is greater than B, return B, otherwise the return X.///sign () method returns the symbol for parameter x, if greater than 0 returns 1, if less than 0 returns 1, otherwise the 0.///ispoweroftwo () method is returned to the power of 2 if the value is a power of 2, which returns TRUE. The Smoothstep () method, like Lerp, interpolates between the minimum and maximum values and gradually fades in at the limit. Three smoothing interpolation the///degtorad () method returns a Radian value that is equal to the angle represented by the parameter degrees. The///clampbottom () method is used to limit the value of x between A and B, and if X is less than a, returns a, otherwise returns X*/THREE. Math = {/******************************************** The following are the function functions provided by the Math object. ****************************************// The *///generateuuid method is used to generate a 36-bit UUID Universal unique identification code (universally unique Identifier). *////<summary>generateuuid</ Summary>///<returns type= "Array" > Return uuid, a 36-bit array Object </returns>generateuuid:function () {//http:/ /www.broofa.com/tools/math.uuid.htmvar chars = ' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz '. Split ("); var uuid = new Array (36 var rnd = 0, R;return function () {for (var i = 0; i <; i + +) {if (i = = 8 | | i = = | | i = = 23) { uuid[i] = '-';}  else if (i = =) {uuid[i] = ' 4 ';} else {if (rnd <= 0x02) rnd = 0x2000000 + (math.random () * 0x1000000) | 0;r = Rnd & 0xf;rnd = rnd >> 4;uuid[i] = chars[(i = = 19)? (R & 0x3) | 0X8:R];}} Return Uuid.join (");//Returns a 36-bit UUID Universal Unique identifier (universally unique Identifier).};} (),//Clamp value to range <a, b>//limit value x is between A and B. The/*///clamp method is used to limit the value of x between A and a, and if X is less than a, returns a. If x is greater than B, return B, otherwise return x*////<summary>clamp</summary>///<param name = "x" type= "number" > Value X</param >///<param name = "a" type= "number" > value A</param>///<param name = "B" type= "number" > Value B</param >///<returns type= "Number" > Returns a If X is less than a. If x is greater than B, return B, otherwise return x</returns>clamp:function (x, a, b) {return (x < a)? A: ((x > B) b:x);/////<p Aram name = "x" type= "number" > Value x</param>},//Clamp value to Range<a, INF)//Limit value X<a/*///clampbottom method is used to limit the value of x between A and B, if X is less than a, returns a, otherwise returns x*////<summary>clampbottom</ Summary>///<param name = "x" type= "number" > value x</param>///<param name = "a" type= "number" > Value a</ Param>///<returns type= "Number" > if x is less than a, return a, otherwise return x</returns>clampbottom:function (x, a) {return x < A ? a:x;//if x is less than a, return a, otherwise return x},//Linear mapping from range &LT;A1, a2> to range &LT;B1, b2>//parameter X in range<a1,a2> to ran ge<b1,b2> linear mapping//TOTO: About linear mapping not clear, there is time to say. The/*///maplinear method is used to return the parameter X in range<a1,a2> to range<b1,b2> Linear mapping *////<summary>maplinear</summary>///<param name = "x" type= "number" > Value x</param>/// <param name = "A1" type= "Number" > value a1</param>///<param name = "A2" type= "Number" > Value a2</param>/ <param name = "B1" type= "number" > value b1</param>///<param name = "B2" type= "number" > Value B2</param >///<returns type= "number" > Return linear mapping x range<a1,a2> to Range<b1,b2></returns>maplinear:function (x, a1, A2, B1, B2) {return B1 + (X-A1) * (B2-B1)/(A2-A1);//return parameter X in RANGE&L T;a1,a2> to range<b1,b2> Linear mapping},//Http://en.wikipedia.org/wiki/smoothstep/*///smoothstep method is similar to Lerp, Interpolates between the minimum and maximum values, and fades in at the limit. Three smoothing interpolation *////<summary>smoothstep</summary>///<param name = "x" type= "number" > Value x</param>/// <param name = "min" type= "number" > Minimum </param>///<param name = "Max" type= "number" > Max </param>/ <returns type= "number" > similar to Lerp, interpolates between the minimum and maximum values and fades in at the limit. </returns>smoothstep:function (x, Min, max) {if (x <= min) return 0;if (x >= max) return 1;x = (x-mi N)/(max-min); return x * x * (3-2 * x);//and Lerp similar to the interpolation between the minimum and maximum values, and gradually fade out at the limit. The},/*///smoothstep method, like Lerp, interpolates between the minimum and maximum values and gradually fades in at the limit. Five smoothing interpolation *////<summary>smoothstep</summary>///<param name = "x" type= "number" > Value x</param>/// <param name = "min" type= "number" > Minimum </param>///<param name = "Max" type= "#"> Max </param>///<returns type= "number" > and lerp similar, interpolation between the minimum and maximum values, and gradually fade out at the limit. </returns>smootherstep:function (x, Min, max) {if (x <= min) return 0;if (x >= max) Return 1;x = (X- min)/(max-min); return x * x * x * (x * (x * 6-15) + 10);//and Lerp similar to the interpolation between the minimum and maximum values, and gradually fade out at the limit.  },//random float from <0, 1> with + bits of randomness//generate 0, to 1 of the stochastic floating-point number with 16-bit size selection range//(Standard Math.random () creates Repetitive patterns when applied over larger space)//Enables the standard Math.random () method to have a greater range of values. The/*///random16 method generates a random floating-point number of 0, to 1, 16-bit size selection range *////<summary>random16</summary>///<returns type= "number" > return random floating point number </returns> Random16:function () {return (65280 * math.random () + 255 * MATH.RANDOM ())/65535;//returns a random floating-point number},//an arbitrary integer from &L T;low, high> interval//generates a random integer from the range of values defined by the parameter Low,high. The/*///randint method generates a random integer by the range of values defined by the parameter Low,high .*////<summary> Randint</summary>///<returns type= "Int" > Returns a random integer. </returns>randint:function (Low, high) {returnLow + Math.floor (Math.random () * (high-low + 1));//returns random integer},//random float from <low, high> interval//by parameter low , the value range of the high definition generates a random floating-point number/*///randint method generates a random floating-point number by the range of values defined by the parameter Low,high .*////<summary>randint</summary>///< Returns type= "float" > return random floating-point number. </returns>randfloat:function (Low, high) {return low + math.random () * (high-l ow);//Returns a random floating-point number},//random float from &LT;-RANGE/2, range/2> interval//generates a [-RANGE/2,RANGE/2] interval for the randomly floating-point number. The/*///randfloatspread method generates a [-RANGE/2,RANGE/2] interval random floating-point number. *////<summary>randfloatspread</summary>///<returns type= "float" > return random floating-point number .</returns> Randfloatspread:function (range) {return range * (0.5-math.random ());//Returns a random floating-point number},/*///sign method returns the symbol for parameter x, if greater than 0 returns 1 if less than 0 return Back-1, otherwise return 0.*////<summary>sign</summary>///<returns type= "Int" > Return symbol. </returns>sign: function (x) {return (x < 0)?-1: (x > 0)? 1:0;//returns the symbol for parameter x, if greater than 0 returns 1, if less than 0 returns-1, otherwise the 0.},/*///degtorad method is returned with the parameter The number degrees represents the angle equal to the radian value. *////<summary&Gt;degtorad</summary>///<returns type= "Number" > returns the Radian value equal to the angle represented by the parameter degrees. </returns>degtorad: function () {var degreetoradiansfactor = Math.pi/180;return function (degrees) {return degrees * degreetoradiansfactor ;//Returns the Radian value that is equal to the angle represented by the parameter degrees.};} (), the/*///radtodeg method returns an angular value that is equal to the radian represented by the parameter radians. *////<summary>radtodeg</summary>///<returns type= " Number "> returns an angular value that is equal to the radian represented by the parameter radians. </returns>radtodeg:function () {var radiantodegreesfactor = 180/math.pi; return function (radians) {return radians * radiantodegreesfactor;//returns the angle value that is equal to the radian represented by the parameter radians}; (),/*///ispoweroftwo whether the method is a power of 2, and returns True if the value is a power of 2. *////<summary>ispoweroftwo</summary>///<returns type= "Number" > returns TRUE if the value is a power of 2. </returns>ispoweroftwo:function (value) {return (value & (value-1)) = = = 0 && value!== 0;//if the value is a power of 2, which returns TRUE. }};


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/math.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 (17) Math/math.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.