Browse Source

adding the lerp to Math class #9728 (#9767)

* adding the lerp to Math class #9728

Adding the precise  interpolation from point x to y using factor t.

* Adding the documentation for Lerp function

Adding the lerp in doc support
koolkap 8 năm trước cách đây
mục cha
commit
aa3df26a2a
2 tập tin đã thay đổi với 19 bổ sung0 xóa
  1. 12 0
      docs/api/math/Math.html
  2. 7 0
      src/math/Math.js

+ 12 - 0
docs/api/math/Math.html

@@ -75,6 +75,18 @@
 		Converts radians to degrees
 		</div>
 
+		<h3>[method:Float lerp]( [page:Float x], [page:Float y], [page:Float t] )</h3>
+		<div>
+		x -- Start point. <br />
+		y -- End point. <br />
+		t -- Closed unit interval from [0,1].
+		</div>
+		<div>
+		Returns a value interpolated from two known points based on the interval.<br/><br/>
+
+		[link:https://en.wikipedia.org/wiki/Linear_interpolation Wikipedia]
+		</div>
+
 		<h3>[method:Float smoothstep]( [page:Float x], [page:Float min], [page:Float max] )</h3>
 		<div>
 		x -- The value to evaluate based on its position between min and max. <br />

+ 7 - 0
src/math/Math.js

@@ -70,6 +70,13 @@ _Math = {
 
 	},
 
+	//https://en.wikipedia.org/wiki/Linear_interpolation
+	
+	lerp: function( x, y, t ){
+
+		return ( 1 - t ) * x + t * y;
+	},
+
 	// http://en.wikipedia.org/wiki/Smoothstep
 
 	smoothstep: function ( x, min, max ) {