Reputation: 262
I've seen an example program, in that to place the position of the Sphere they are doing some mathematical calculations. In that I've seen THREE.Math.mapLinear()
is being used. If I pass the parameters as:
var x = THREE.Math.mapLinear(-70.16, -150, 150, 0, 1366);
then the value of x
is showing 363.51.
Please can anyone explain what exactly happening?
Upvotes: 2
Views: 1002
Reputation: 32212
The mapLinear
function takes two ranges of numbers (a1
-a2
and b1
-b2
), and an offset (x
):
mapLinear: function ( x, a1, a2, b1, b2 ) {
return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
}
It works out how far through the range of a
that x
is, and calculates the equivalent position in b
and returns it.
With your input, -70.16
is roughly one quarter (23.387%) of the way through the range -150
to 150
. The function returns 363.51
, which is the equivalent roughly one quarter (23.387%) of the way through the range 0
to 1366
.
Upvotes: 6