-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscaleTest.js
72 lines (49 loc) · 1.49 KB
/
scaleTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*Suppose your linear function is
f(x) = ax + b.
Then f(0.1) = 0.25,
and f(1) = 0.75.
a * 0.1 + b = 0.25,
a * 1 + b = 0.75,
so b = 0.75 - a.
a * 0.1 + (0.75 - a) = 0.25, so a = 5 / 9, (-.9a = -.5)
and so b = 7 / 36. Checking, (5 / 9) * 0.1 + 7 / 36 = 0.25, and (5 / 9) + 7 / 36 = 0.75.
a = .1 b = 1
c = .25 d = .75
But anyway, you can conclude by yourself that n = (c - d) / (a - b), and m = c - a * n, so you know how to find both n and m.
n = .555556 -- scale
m = .19444 -- offset
*/
// y = 128 goes form -64, 64
// scaling from -PI, PI
var n = (-Math.PI - Math.PI) / (-64 - 64);
var m = -Math.PI - (-64 * n);
for(var i = -64; i <= 64; i += 1){
console.log(i + " : " + (i * n + m));
}
/*
var dp = 2;
var num = [];
for(var i = 0; i <= 12; i++){
num[i] = i;
}
var initialScale = .01;
var scale = 0;
var offset = 0;
var ostart = num[0], ofinish = num[num.length-1];
var pstart = 0, pfinish = Math.PI * 2;
for(var s = 1; s <= 4; s++){
var out = "";
//we don't want to offset the original scaling
start = (pfinish / 2) - (pfinish / Math.pow(2, s));
finish = (pfinish / 2) + (pfinish / Math.pow(2, s));
console.log(start + " : " + finish + " : " + ostart + " : " + ofinish);
scale = ( start - finish) / ( ostart - ofinish );
offset = start - ( ostart * scale );
for(var i = 0; i < num.length; i++){
out += " " +i + ": " + ( (num[i] * scale + offset).toFixed(dp) );
}
out += " -- scale " + (scale.toFixed(dp));
out += " -- offset " +(offset.toFixed(dp));
console.log(out);
}
*/